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

export default async function delWidget({
    params = {}, pg = pgClients.client, user = {},
}, reply) {
    const { uid } = user;

    if (!uid) {
        return reply.status(401).send('unauthorized');
    }

    if (!params.map) {
        return reply.status(400).send('not enough params: map id');
    }

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