UNPKG

stackpress

Version:

Incept is a content management framework.

26 lines (25 loc) 684 B
import { toErrorResponse } from '../helpers.js'; import detail from './detail.js'; import update from './update.js'; export default async function remove(model, engine, ids) { const active = model.active?.name; if (active) { return await update(model, engine, ids, { [active]: false }); } const row = await detail(model, engine, ids); if (row.code !== 200) { return row; } const remove = engine.delete(model.snake); for (const column of model.ids) { remove.where(`${column.snake} = ?`, [ids[column.name]]); } try { await remove; } catch (e) { return toErrorResponse(e); } return row; } ;