Page MenuHomeSealhub

item-delete.ts
No OneTemporary

item-delete.ts

import { toKebabCase, toPascalCase } from "js-convert-case";
import { curryImportPath } from "../../utils/import-path.js";
import { formatWithPrettier } from "../../utils/prettier.js";
export function itemDeleteTemplate(
delete_action_name: string,
collection_name: string,
newfilefullpath: string,
list_action_name: string
): Promise<string> {
const importPath = curryImportPath(newfilefullpath);
const result = `import type { Context } from "koa";
import { Mountable } from "@sealcode/sealgen";
import type Router from "@koa/router";
import { ${toPascalCase(collection_name)} } from "${importPath(
"src/back/collections/collections.js"
)}";
import { ${list_action_name}URL } from "${importPath(
"src/back/routes/urls.js"
)}";
export const actionName = "${delete_action_name}";
export default new (class ${delete_action_name}Redirect extends Mountable {
canAccess = async (ctx: Context) => {
const policy = ${toPascalCase(collection_name)}.getPolicy("edit");
const response = await policy.check(ctx.$context);
return { canAccess: response?.allowed || false, message: response?.reason || "" };
};
mount(router: Router, path: string) {
router.get(path, async (ctx) => {
await ctx.$app.collections["${toKebabCase(
collection_name
)}"].removeByID(ctx.$context, ctx.params.id!);
ctx.status = 302;
ctx.redirect(${list_action_name}URL);
});
}
})();
`;
return formatWithPrettier(result);
}

File Metadata

Mime Type
text/x-java
Expires
Sat, Jun 7, 23:22 (1 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
624878
Default Alt Text
item-delete.ts (1 KB)

Event Timeline