Add ability to delete configurations
This commit is contained in:
@@ -157,6 +157,9 @@ export const app = new Elysia()
|
||||
params: t.Object({ id: t.String() }),
|
||||
body: t.Object({ name: t.String(), datasetId: t.String(), params: StandardsParamsSchema })
|
||||
})
|
||||
.delete("/configs/:id", async ({ params: { id } }) => {
|
||||
await s.Standards.Configs.delete(id);
|
||||
}, { params: t.Object({ id: t.String() }) })
|
||||
.get("/datasets", async () => {
|
||||
return await s.Standards.Datasets.list();
|
||||
})
|
||||
|
||||
@@ -61,6 +61,18 @@ class StandardsConfigService {
|
||||
.execute();
|
||||
if (result[0]?.numUpdatedRows === 0n) throw new Error(`No config with id "${id}"`);
|
||||
}
|
||||
|
||||
async delete(id: string) {
|
||||
const { count } = await db.selectFrom("standards_configs")
|
||||
.select(db.fn.countAll<number>().as("count"))
|
||||
.executeTakeFirstOrThrow();
|
||||
if (Number(count) <= 1) throw new Error("Cannot delete the last remaining standards configuration");
|
||||
|
||||
const result = await db.deleteFrom("standards_configs")
|
||||
.where("id", "=", id)
|
||||
.execute();
|
||||
if (result[0]?.numDeletedRows === 0n) throw new Error(`No config with id "${id}"`);
|
||||
}
|
||||
}
|
||||
|
||||
class StandardsDatasetService {
|
||||
|
||||
Reference in New Issue
Block a user