import { dataDelete, pgClients } from "@opengis/fastify-table/utils.js";

export default async function deleteGisRegistry({
    params = {}, pg = pgClients.client, user = {},
}, reply) {
    const id = await pg.query('select register_id from gis.registers where register_key=$1', [params.slug]).then(el => el.rows?.[0]?.register_id) || params.slug;

    const row = await dataDelete({
        pg,
        id,
        table: 'gis.registers',
        uid: user?.uid,
    });
    return reply.status(200).send(row);
}