dataAttributes.delete endpoint

This commit is contained in:
Tom Moor committed 2024-07-27 16:21:11 -04:00
1 parent 8120ef0ce8
commit c950788ef1
2 files changed
+33

No files matched your search

@@ -111,4 +111,29 @@ router.post(
}
);
router.post(
"dataAttributes.delete",
auth({ role: UserRole.Admin }),
validate(T.DataAttributesDeleteSchema),
transaction(),
async (ctx: APIContext<T.DataAttributesDeleteReq>) => {
const { id } = ctx.input.body;
const { user } = ctx.state.auth;
const { transaction } = ctx.state;
const dataAttribute = await DataAttribute.findByPk(id, {
lock: transaction.LOCK.UPDATE,
rejectOnEmpty: true,
transaction,
});
authorize(user, "delete", dataAttribute);
await dataAttribute.destroy({ transaction });
ctx.body = {
success: true,
};
}
);
export default router;
@@ -108,3 +108,11 @@ export const DataAttributesUpdateSchema = BaseSchema.extend({
export type DataAttributesUpdateReq = z.infer<
typeof DataAttributesUpdateSchema
>;
export const DataAttributesDeleteSchema = BaseSchema.extend({
body: BaseIdSchema,
});
export type DataAttributesDeleteReq = z.infer<
typeof DataAttributesDeleteSchema
>;