Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F5665665
item-delete.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
item-delete.ts
View Options
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
Details
Attached
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)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment