create-arkos 2.0.0-next.17 → 2.0.0-next.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/index.js +4 -0
  2. package/dist/index.js.map +1 -1
  3. package/dist/utils/project-config-inquirer.js +40 -33
  4. package/dist/utils/project-config-inquirer.js.map +1 -1
  5. package/dist/utils/template-compiler.js +16 -11
  6. package/dist/utils/template-compiler.js.map +1 -1
  7. package/package.json +1 -1
  8. package/templates/basic/.env.hbs +5 -1
  9. package/templates/basic/.gitignore.hbs +2 -0
  10. package/templates/basic/README.md.hbs +1 -1
  11. package/templates/basic/arkos.config.ts.hbs +16 -3
  12. package/templates/basic/jsconfig.json.hbs +3 -3
  13. package/templates/basic/package.json.hbs +31 -13
  14. package/templates/basic/prisma/schema/__tests__/user-role.prisma.hbs.test.ts +2 -2
  15. package/templates/basic/prisma/schema/__tests__/user.prisma.hbs.test.ts +2 -2
  16. package/templates/basic/prisma/schema/auth-permission.prisma.hbs +3 -9
  17. package/templates/basic/prisma/schema/auth-role.prisma.hbs +2 -2
  18. package/templates/basic/prisma/schema/schema.prisma.hbs +2 -3
  19. package/templates/basic/prisma/schema/user-permission.prisma.hbs +18 -0
  20. package/templates/basic/prisma/schema/user.prisma.hbs +4 -2
  21. package/templates/basic/prisma.config.ts.hbs +10 -0
  22. package/templates/basic/public/favicon.ico +0 -0
  23. package/templates/basic/src/app.ts.hbs +9 -7
  24. package/templates/basic/src/modules/auth/auth.policy.ts.hbs +1 -1
  25. package/templates/basic/src/modules/auth/auth.router.ts.hbs +72 -7
  26. package/templates/basic/src/modules/auth/dtos/login.dto.ts.hbs +1 -1
  27. package/templates/basic/src/modules/auth/dtos/signup.dto.ts.hbs +1 -1
  28. package/templates/basic/src/modules/auth/dtos/update-me.dto.ts.hbs +1 -1
  29. package/templates/basic/src/modules/auth/dtos/update-password.dto.ts.hbs +1 -1
  30. package/templates/basic/src/modules/auth-permission/auth-permission.router.ts.hbs +39 -7
  31. package/templates/basic/src/modules/auth-permission/auth-permission.service.ts.hbs +4 -6
  32. package/templates/basic/src/modules/auth-permission/dtos/create-auth-permission.dto.ts.hbs +6 -5
  33. package/templates/basic/src/modules/auth-permission/dtos/{query-auth-role.dto.ts.hbs → query-auth-permission.dto.ts.hbs} +1 -1
  34. package/templates/basic/src/modules/auth-permission/dtos/update-auth-permission.dto.ts.hbs +17 -4
  35. package/templates/basic/src/modules/auth-role/auth-role.router.ts.hbs +38 -6
  36. package/templates/basic/src/modules/auth-role/auth-role.service.ts.hbs +4 -6
  37. package/templates/basic/src/modules/auth-role/dtos/create-auth-role.dto.ts.hbs +1 -1
  38. package/templates/basic/src/modules/auth-role/dtos/query-auth-role.dto.ts.hbs +1 -1
  39. package/templates/basic/src/modules/auth-role/dtos/update-auth-role.dto.ts.hbs +2 -1
  40. package/templates/basic/src/modules/file-upload/file-upload.router.ts.hbs +28 -8
  41. package/templates/basic/src/modules/user/dtos/create-user.dto.ts.hbs +3 -3
  42. package/templates/basic/src/modules/user/dtos/update-user.dto.ts.hbs +3 -3
  43. package/templates/basic/src/modules/user/user.router.ts.hbs +91 -7
  44. package/templates/basic/src/modules/user/user.service.ts.hbs +4 -6
  45. package/templates/basic/src/router.ts.hbs +2 -2
  46. package/templates/basic/src/server.ts.hbs +8 -0
  47. package/templates/basic/src/utils/prisma/index.ts.hbs +48 -2
  48. package/templates/basic/src/utils/validation/api-actions.ts.hbs +2 -2
  49. package/templates/basic/tsconfig.json.hbs +5 -4
  50. package/templates/basic/src/loadables.ts.hbs +0 -29
  51. package/templates/basic/src/modules/auth/auth.route-hook.ts.hbs +0 -66
  52. package/templates/basic/src/modules/auth-permission/auth-permission.route-hook.ts.hbs +0 -35
  53. package/templates/basic/src/modules/auth-role/auth-role.route-hook.ts.hbs +0 -35
  54. package/templates/basic/src/modules/file-upload/file-upload.route-hook.ts.hbs +0 -23
  55. package/templates/basic/src/modules/user/user.route-hook.ts.hbs +0 -88
@@ -1,9 +1,8 @@
1
1
  generator client {
2
- provider = "prisma-client-js"
2
+ provider = "prisma-client"
3
+ output = "../src/generated/prisma"
3
4
  }
4
5
 
5
6
  datasource db {
6
7
  provider = "{{prisma.provider}}"
7
- url = env("DATABASE_URL")
8
8
  }
9
-
@@ -0,0 +1,18 @@
1
+ model UserPermission {
2
+ id String @id @default(uuid())
3
+ createdAt DateTime @default(now())
4
+ updatedAt DateTime @updatedAt
5
+
6
+ effect UserPermissionEffect @default(Allow)
7
+ userId String
8
+ user User @relation(fields: [userId], references: [id])
9
+ permissionId String
10
+ permission AuthPermission @relation(fields: [permissionId], references: [id])
11
+
12
+ @@unique([userId, permissionId])
13
+ }
14
+
15
+ enum UserPermissionEffect {
16
+ Allow
17
+ Deny
18
+ }
@@ -1,4 +1,4 @@
1
- {{#if (neq authentication.type "define later")}}
1
+ {{#if (neq authentication.type "none")}}
2
2
  model User {
3
3
  id String {{{prisma.idDatabaseType}}}
4
4
  {{authentication.usernameField}} String @unique
@@ -30,9 +30,11 @@ model User {
30
30
  {{/if}}
31
31
  {{/if}}
32
32
  {{/if}}
33
+ {{#if (eq authentication.type "dynamic")}}
34
+ permissions UserPermission[]
35
+ {{/if}}
33
36
  createdAt DateTime @default(now())
34
37
  updatedAt DateTime @updatedAt
35
- // other fields for your application
36
38
  }
37
39
 
38
40
  {{#if (eq authentication.type "static")}}
@@ -0,0 +1,10 @@
1
+ import { loadEnvironmentVariables } from "arkos/utils";
2
+ loadEnvironmentVariables()
3
+
4
+ import { defineConfig, env } from "prisma/config";
5
+
6
+ export default defineConfig({
7
+ datasource: {
8
+ url: env("DATABASE_URL"),
9
+ },
10
+ });
@@ -1,12 +1,14 @@
1
1
  import arkos from "arkos";
2
- import router from "@/src/router"
3
- import loadables from "@/src/loadables"
2
+ import router from "@/src/router";
4
3
 
5
- const app = arkos()
4
+ const app = arkos();
6
5
 
7
- app.set("trust proxy", 1)
6
+ app.set("trust proxy", 1);
7
+ app.use(router);
8
8
 
9
- app.load(loadables)
10
- app.use(router)
9
+ {{#if (eq entryPoint "src/app")}}
10
+ app.listen();
11
+ {{else}}
12
+ export default app;
13
+ {{/if}}
11
14
 
12
- app.listen()
@@ -1,5 +1,5 @@
1
1
  import { ArkosPolicy } from "arkos";
2
2
 
3
- const authPolicy = ArkosPolicy("auth-permission")
3
+ const authPolicy = ArkosPolicy("auth")
4
4
 
5
5
  export default authPolicy;
@@ -1,11 +1,76 @@
1
- import { ArkosRouter } from "arkos";
2
- {{#if authentication}}
3
- import authPolicy from "@/src/modules/auth/auth.policy";
1
+ import { ArkosRouter, ArkosRouteHook } from 'arkos';
2
+ {{#if (neq authentication.type "none")}}
3
+ import authPolicy from '@/src/modules/auth/auth.policy';
4
4
  {{/if}}
5
+ {{#if validation.type}}
6
+ import LoginDto from '@/src/modules/auth/dtos/login.dto';
7
+ import SignupDto from '@/src/modules/auth/dtos/signup.dto';
8
+ import UpdateMeDto from '@/src/modules/auth/dtos/update-me.dto';
9
+ import UpdatePasswordDto from '@/src/modules/auth/dtos/update-password.dto';
10
+ {{/if}}
11
+
12
+ const authRouteHook = ArkosRouteHook("auth");
13
+
14
+ authRouteHook.login({
15
+ {{#if validation.type}}validation: { body: LoginDto },{{/if}}
16
+ });
17
+
18
+ authRouteHook.signup({
19
+ {{#if validation.type}}validation: { body: SignupDto },{{/if}}
20
+ prismaArgs: {
21
+ omit: { password: true },
22
+ },
23
+ });
24
+
25
+ authRouteHook.getMe({
26
+ prismaArgs: {
27
+ omit: { password: true },
28
+ {{#if (eq authentication.type "dynamic")}}
29
+ include: {
30
+ {{#if authentication.multipleRoles}}
31
+ roles: {
32
+ include: {
33
+ role: {
34
+ include: {
35
+ permissions: true,
36
+ },
37
+ },
38
+ },
39
+ },
40
+ {{else}}
41
+ role: {
42
+ include: {
43
+ role: {
44
+ include: {
45
+ permissions: true,
46
+ },
47
+ },
48
+ },
49
+ },
50
+ {{/if}}
51
+ },
52
+ {{/if}}
53
+ },
54
+ });
55
+
56
+ authRouteHook.updateMe({
57
+ {{#if validation.type}}validation: { body: UpdateMeDto },{{/if}}
58
+ prismaArgs: {
59
+ omit: { password: true },
60
+ },
61
+ });
62
+
63
+ authRouteHook.updatePassword({
64
+ {{#if validation.type}}validation: { body: UpdatePasswordDto },{{/if}}
65
+ });
66
+
67
+ authRouteHook.logout({});
68
+
69
+ const authRouter = ArkosRouter({
70
+ prefix: "/auth",
71
+ openapi: { tags: ["Authentication"] },
72
+ });
5
73
 
6
- const authRouter = ArkosRouter({
7
- prefix: "/auth",
8
- openapi: { tags: ["Authentication"] }
9
- });
74
+ authRouter.load(authRouteHook);
10
75
 
11
76
  export default authRouter;
@@ -8,7 +8,7 @@ const LoginDto = z.object({
8
8
 
9
9
  export default LoginDto;
10
10
  {{#if typescript}}
11
- export type LoginDtoType = z.infer<typeof LoginDto>;
11
+ export type LoginDto = z.infer<typeof LoginDto>;
12
12
  {{/if}}
13
13
  {{/if}}
14
14
  {{#if (eq validation.type "class-validator")}}
@@ -8,7 +8,7 @@ const SignupDto = z.object({
8
8
 
9
9
  export default SignupDto;
10
10
  {{#if typescript}}
11
- export type SignupDtoType = z.infer<typeof SignupDto>;
11
+ export type SignupDto = z.infer<typeof SignupDto>;
12
12
  {{/if}}
13
13
  {{/if}}
14
14
  {{#if (eq validation.type "class-validator")}}
@@ -7,7 +7,7 @@ const UpdateMeDto = z.object({
7
7
 
8
8
  export default UpdateMeDto;
9
9
  {{#if typescript}}
10
- export type UpdateMeDtoType = z.infer<typeof UpdateMeDto>;
10
+ export type UpdateMeDto = z.infer<typeof UpdateMeDto>;
11
11
  {{/if}}
12
12
  {{/if}}
13
13
  {{#if (eq validation.type "class-validator")}}
@@ -8,7 +8,7 @@ const UpdatePasswordDto = z.object({
8
8
 
9
9
  export default UpdatePasswordDto;
10
10
  {{#if typescript}}
11
- export type UpdatePasswordDtoType = z.infer<typeof UpdatePasswordDto>;
11
+ export type UpdatePasswordDto = z.infer<typeof UpdatePasswordDto>;
12
12
  {{/if}}
13
13
  {{/if}}
14
14
  {{#if (eq validation.type "class-validator")}}
@@ -1,11 +1,43 @@
1
- import { ArkosRouter } from "arkos";
2
- {{#if authentication}}
3
- import authPermissionPolicy from "@/src/modules/auth-permission/auth-permission.policy";
1
+ import { ArkosRouter, ArkosRouteHook } from 'arkos';
2
+ {{#if (neq authentication.type "none")}}
3
+ import authPermissionPolicy from '@/src/modules/auth-permission/auth-permission.policy';
4
4
  {{/if}}
5
+ {{#if validation.type}}
6
+ import CreateAuthPermissionDto from '@/src/modules/auth-permission/dtos/create-auth-permission.dto';
7
+ import UpdateAuthPermissionDto from '@/src/modules/auth-permission/dtos/update-auth-permission.dto';
8
+ import QueryAuthPermissionDto from '@/src/modules/auth-permission/dtos/query-auth-permission.dto';
9
+ {{/if}}
10
+
11
+ const authPermissionRouteHook = ArkosRouteHook("auth-permission");
12
+
13
+ authPermissionRouteHook.createOne({
14
+ {{#if validation.type}}validation: { body: CreateAuthPermissionDto },{{/if}}
15
+ {{#if (neq authentication.type "none")}}authentication: authPermissionPolicy.Create,{{/if}}
16
+ });
17
+
18
+ authPermissionRouteHook.findOne({
19
+ {{#if (neq authentication.type "none")}}authentication: authPermissionPolicy.View,{{/if}}
20
+ });
21
+
22
+ authPermissionRouteHook.findMany({
23
+ {{#if validation.type}}validation: { query: QueryAuthPermissionDto },{{/if}}
24
+ {{#if (neq authentication.type "none")}}authentication: authPermissionPolicy.View,{{/if}}
25
+ });
26
+
27
+ authPermissionRouteHook.updateOne({
28
+ {{#if validation.type}}validation: { body: UpdateAuthPermissionDto },{{/if}}
29
+ {{#if (neq authentication.type "none")}}authentication: authPermissionPolicy.Update,{{/if}}
30
+ });
31
+
32
+ authPermissionRouteHook.deleteOne({
33
+ {{#if (neq authentication.type "none")}}authentication: authPermissionPolicy.Delete,{{/if}}
34
+ });
35
+
36
+ const authPermissionRouter = ArkosRouter({
37
+ prefix: "/auth-permissions",
38
+ openapi: { tags: ["Auth Permissions"] },
39
+ });
5
40
 
6
- const authPermissionRouter = ArkosRouter({
7
- prefix: "/auth-permissions",
8
- openapi: { tags: ["Auth Permissions"] }
9
- });
41
+ authPermissionRouter.load(authPermissionRouteHook);
10
42
 
11
43
  export default authPermissionRouter;
@@ -1,11 +1,9 @@
1
- import { BaseService } from "arkos/services";
2
- {{#if typescript}}
3
- import { Prisma } from "@prisma/client"
1
+ import { ArkosPrismaService } from "arkos/services";
4
2
 
5
- class AuthPermissionService extends BaseService<"auth-permission"> {}
3
+ {{#if typescript}}
4
+ class AuthPermissionService extends ArkosPrismaService<"auth-permission"> {}
6
5
  {{else}}
7
-
8
- class AuthPermissionService extends BaseService {}
6
+ class AuthPermissionService extends ArkosPrismaService {}
9
7
  {{/if}}
10
8
 
11
9
  const authPermissionService = new AuthPermissionService("auth-permission");
@@ -4,19 +4,19 @@ import { z } from 'zod';
4
4
  const CreateAuthPermissionDto = z.object({
5
5
  resource: z.string().min(1, 'Resource is required'),
6
6
  action: z.string().default('View'),
7
- role: z.object({
7
+ roles: z.array(z.object({
8
8
  id: z.string().min(1, 'Role ID is required'),
9
- }),
9
+ })).optional(),
10
10
  description: z.string().optional(),
11
11
  });
12
12
 
13
13
  export default CreateAuthPermissionDto;
14
14
  {{#if typescript}}
15
- export type CreateAuthPermissionDtoType = z.infer<typeof CreateAuthPermissionDto>;
15
+ export type CreateAuthPermissionDto = z.infer<typeof CreateAuthPermissionDto>;
16
16
  {{/if}}
17
17
  {{/if}}
18
18
  {{#if (eq validation.type "class-validator")}}
19
- import { IsString, IsNotEmpty, IsOptional, IsValidateNested } from 'class-validator';
19
+ import { IsString, IsNotEmpty, IsOptional, IsArray, ValidateNested } from 'class-validator';
20
20
  import { Type, Transform } from 'class-transformer';
21
21
  import 'reflect-metadata';
22
22
 
@@ -35,7 +35,8 @@ export default class CreateAuthPermissionDto {
35
35
  @Transform(({ value }) => value || 'View')
36
36
  action?: string = 'View';
37
37
 
38
- @ValidateNested()
38
+ @ValidateNested({ each: true })
39
+ @IsArray()
39
40
  @Type(() => RoleConnectDto)
40
41
  @IsOptional()
41
42
  roles?: RoleConnectDto[];
@@ -18,7 +18,7 @@ const QueryAuthPermissionDto = z.object({
18
18
 
19
19
  export default QueryAuthPermissionDto;
20
20
  {{#if typescript}}
21
- export type QueryAuthPermissionDtoType = z.infer<typeof QueryAuthPermissionDto>;
21
+ export type QueryAuthPermissionDto = z.infer<typeof QueryAuthPermissionDto>;
22
22
  {{/if}}
23
23
  {{/if}}
24
24
  {{#if (eq validation.type "class-validator")}}
@@ -5,18 +5,27 @@ const UpdateAuthPermissionDto = z.object({
5
5
  resource: z.string().optional(),
6
6
  action: z.string().optional(),
7
7
  description: z.string().optional(),
8
+ roles: z.array(z.object({
9
+ id: z.string().min(1, 'Role ID is required'),
10
+ })).optional(),
8
11
  });
9
12
 
10
13
  export default UpdateAuthPermissionDto;
11
14
  {{#if typescript}}
12
- export type UpdateAuthPermissionDtoType = z.infer<typeof UpdateAuthPermissionDto>;
15
+ export type UpdateAuthPermissionDto = z.infer<typeof UpdateAuthPermissionDto>;
13
16
  {{/if}}
14
17
  {{/if}}
15
18
  {{#if (eq validation.type "class-validator")}}
16
- import { IsString, IsOptional } from 'class-validator';
17
- import { Transform } from 'class-transformer';
19
+ import { IsString, IsOptional, IsArray, ValidateNested } from 'class-validator';
20
+ import { Transform, Type } from 'class-transformer';
18
21
  import 'reflect-metadata';
19
22
 
23
+ class RoleConnectDto {
24
+ @IsString()
25
+ @IsNotEmpty({ message: 'Role ID is required' })
26
+ id!: string;
27
+ }
28
+
20
29
  export default class UpdateAuthPermissionDto {
21
30
  @IsOptional()
22
31
  @IsString()
@@ -25,7 +34,11 @@ export default class UpdateAuthPermissionDto {
25
34
  @IsOptional()
26
35
  @IsString()
27
36
  @Transform(({ value }) => String(value))
28
- action?: string
37
+ action?: string;
38
+
39
+ @IsOptional()
40
+ @IsString()
41
+ description?: string;
29
42
 
30
43
  @ValidateNested({ each: true })
31
44
  @IsArray()
@@ -1,11 +1,43 @@
1
- import { ArkosRouter } from "arkos";
2
- {{#if authentication}}
3
- import authRolePolicy from "@/src/modules/auth-role/auth-role.policy";
1
+ import { ArkosRouter, ArkosRouteHook } from 'arkos';
2
+ {{#if (neq authentication.type "none")}}
3
+ import authRolePolicy from '@/src/modules/auth-role/auth-role.policy';
4
4
  {{/if}}
5
+ {{#if validation.type}}
6
+ import CreateAuthRoleDto from '@/src/modules/auth-role/dtos/create-auth-role.dto';
7
+ import UpdateAuthRoleDto from '@/src/modules/auth-role/dtos/update-auth-role.dto';
8
+ import QueryAuthRoleDto from '@/src/modules/auth-role/dtos/query-auth-role.dto';
9
+ {{/if}}
10
+
11
+ const authRoleRouteHook = ArkosRouteHook("auth-role");
12
+
13
+ authRoleRouteHook.createOne({
14
+ {{#if validation.type}}validation: { body: CreateAuthRoleDto },{{/if}}
15
+ {{#if (neq authentication.type "none")}}authentication: authRolePolicy.Create,{{/if}}
16
+ });
17
+
18
+ authRoleRouteHook.findOne({
19
+ {{#if (neq authentication.type "none")}}authentication: authRolePolicy.View,{{/if}}
20
+ });
21
+
22
+ authRoleRouteHook.findMany({
23
+ {{#if validation.type}}validation: { query: QueryAuthRoleDto },{{/if}}
24
+ {{#if (neq authentication.type "none")}}authentication: authRolePolicy.View,{{/if}}
25
+ });
26
+
27
+ authRoleRouteHook.updateOne({
28
+ {{#if validation.type}}validation: { body: UpdateAuthRoleDto },{{/if}}
29
+ {{#if (neq authentication.type "none")}}authentication: authRolePolicy.Update,{{/if}}
30
+ });
31
+
32
+ authRoleRouteHook.deleteOne({
33
+ {{#if (neq authentication.type "none")}}authentication: authRolePolicy.Delete,{{/if}}
34
+ });
5
35
 
6
36
  const authRoleRouter = ArkosRouter({
7
- prefix: "/auth-roles",
8
- openapi: { tags: ["Auth Roles"] }
9
- });
37
+ prefix: "/auth-roles",
38
+ openapi: { tags: ["Auth Roles"] },
39
+ });
40
+
41
+ authRoleRouter.load(authRoleRouteHook);
10
42
 
11
43
  export default authRoleRouter;
@@ -1,11 +1,9 @@
1
- import { BaseService } from "arkos/services";
2
- {{#if typescript}}
3
- import { Prisma } from "@prisma/client"
1
+ import { ArkosPrismaService } from "arkos/services";
4
2
 
5
- class AuthRoleService extends BaseService<"auth-role"> {}
3
+ {{#if typescript}}
4
+ class AuthRoleService extends ArkosPrismaService<"auth-role"> {}
6
5
  {{else}}
7
-
8
- class AuthRoleService extends BaseService {}
6
+ class AuthRoleService extends ArkosPrismaService {}
9
7
  {{/if}}
10
8
 
11
9
  const authRoleService = new AuthRoleService("auth-role");
@@ -15,7 +15,7 @@ const CreateAuthRoleDto = z.object({
15
15
 
16
16
  export default CreateAuthRoleDto;
17
17
  {{#if typescript}}
18
- export type CreateAuthRoleDtoType = z.infer<typeof CreateAuthRoleDto>;
18
+ export type CreateAuthRoleDto = z.infer<typeof CreateAuthRoleDto>;
19
19
  {{/if}}
20
20
  {{/if}}
21
21
  {{#if (eq validation.type "class-validator")}}
@@ -22,7 +22,7 @@ const QueryAuthRoleDto = z.object({
22
22
 
23
23
  export default QueryAuthRoleDto;
24
24
  {{#if typescript}}
25
- export type QueryAuthRoleDtoType = z.infer<typeof QueryAuthRoleDto>;
25
+ export type QueryAuthRoleDto = z.infer<typeof QueryAuthRoleDto>;
26
26
  {{/if}}
27
27
  {{/if}}
28
28
  {{#if (eq validation.type "class-validator")}}
@@ -17,7 +17,7 @@ const UpdateAuthRoleDto = z.object({
17
17
 
18
18
  export default UpdateAuthRoleDto;
19
19
  {{#if typescript}}
20
- export type UpdateAuthRoleDtoType = z.infer<typeof UpdateAuthRoleDto>;
20
+ export type UpdateAuthRoleDto = z.infer<typeof UpdateAuthRoleDto>;
21
21
  {{/if}}
22
22
  {{/if}}
23
23
  {{#if (eq validation.type "class-validator")}}
@@ -27,6 +27,7 @@ import 'reflect-metadata';
27
27
 
28
28
  export enum ApiAction {
29
29
  connect = 'connect',
30
+ disconnect = 'disconnect',
30
31
  delete = 'delete',
31
32
  create = 'create',
32
33
  update = 'update'
@@ -1,12 +1,32 @@
1
- import { ArkosRouter } from "arkos";
2
- {{#if authentication}}
3
- import fileUploadPolicy from "@/src/modules/file-upload/file-upload.policy";
1
+ import { ArkosRouter, ArkosRouteHook } from 'arkos';
2
+ {{#if (neq authentication.type "none")}}
3
+ import fileUploadPolicy from '@/src/modules/file-upload/file-upload.policy';
4
4
  {{/if}}
5
- import config from "@/arkos.config"
5
+ import config from '@/arkos.config';
6
6
 
7
- const fileUploadRouter = ArkosRouter({
8
- prefix: config?.fileUpload?.baseRoute,
9
- openapi: { tags: ["File Uploads"] }
10
- });
7
+ const fileUploadRouteHook = ArkosRouteHook("file-upload");
8
+
9
+ fileUploadRouteHook.findFile({
10
+ {{#if (neq authentication.type "none")}}authentication: fileUploadPolicy.View,{{/if}}
11
+ });
12
+
13
+ fileUploadRouteHook.uploadFile({
14
+ {{#if (neq authentication.type "none")}}authentication: fileUploadPolicy.Create,{{/if}}
15
+ });
16
+
17
+ fileUploadRouteHook.updateFile({
18
+ {{#if (neq authentication.type "none")}}authentication: fileUploadPolicy.Update,{{/if}}
19
+ });
20
+
21
+ fileUploadRouteHook.deleteFile({
22
+ {{#if (neq authentication.type "none")}}authentication: fileUploadPolicy.Delete,{{/if}}
23
+ });
24
+
25
+ const fileUploadRouter = ArkosRouter({
26
+ prefix: config?.fileUpload?.baseRoute,
27
+ openapi: { tags: ["File Upload"] },
28
+ });
29
+
30
+ fileUploadRouter.load(fileUploadRouteHook);
11
31
 
12
32
  export default fileUploadRouter;
@@ -20,9 +20,9 @@ const CreateUserDto = z.object({
20
20
  role: z.string(),
21
21
  {{else}}
22
22
  {{#if authentication.multipleRoles}}
23
- roles: z.array(z.nativeEnum(UserRole)),
23
+ roles: z.array(z.enum(UserRole)),
24
24
  {{else}}
25
- role: z.nativeEnum(UserRole),
25
+ role: z.enum(UserRole),
26
26
  {{/if}}
27
27
  {{/if}}
28
28
  {{else}}
@@ -40,7 +40,7 @@ const CreateUserDto = z.object({
40
40
 
41
41
  export default CreateUserDto;
42
42
  {{#if typescript}}
43
- export type CreateUserDtoType = z.infer<typeof CreateUserDto>;
43
+ export type CreateUserDto = z.infer<typeof CreateUserDto>;
44
44
  {{/if}}
45
45
  {{/if}}
46
46
  {{#if (eq validation.type "class-validator")}}
@@ -22,9 +22,9 @@ const UpdateUserDto = z.object({
22
22
  role: z.string().optional(),
23
23
  {{else}}
24
24
  {{#if authentication.multipleRoles}}
25
- roles: z.array(z.nativeEnum(UserRole)).optional(),
25
+ roles: z.array(z.enum(UserRole)).optional(),
26
26
  {{else}}
27
- role: z.nativeEnum(UserRole).optional(),
27
+ role: z.enum(UserRole).optional(),
28
28
  {{/if}}
29
29
  {{/if}}
30
30
  {{else}}
@@ -46,7 +46,7 @@ const UpdateUserDto = z.object({
46
46
 
47
47
  export default UpdateUserDto;
48
48
  {{#if typescript}}
49
- export type UpdateUserDtoType = z.infer<typeof UpdateUserDto>;
49
+ export type UpdateUserDto = z.infer<typeof UpdateUserDto>;
50
50
  {{/if}}
51
51
  {{/if}}
52
52
  {{#if (eq validation.type "class-validator")}}
@@ -1,11 +1,95 @@
1
- import { ArkosRouter } from "arkos";
2
- {{#if authentication}}
3
- import userPolicy from "@/src/modules/user/user.policy";
1
+ import { ArkosRouter, ArkosRouteHook } from 'arkos';
2
+ {{#if (neq authentication.type "none")}}
3
+ import userPolicy from '@/src/modules/user/user.policy';
4
4
  {{/if}}
5
+ {{#if validation.type}}
6
+ import CreateUserDto from '@/src/modules/user/dtos/create-user.dto';
7
+ import UpdateUserDto from '@/src/modules/user/dtos/update-user.dto';
8
+ {{/if}}
9
+
10
+ const userRouteHook = ArkosRouteHook("user");
11
+
12
+ userRouteHook.createOne({
13
+ {{#if validation.type}}validation: { body: CreateUserDto },{{/if}}
14
+ {{#if (neq authentication.type "none")}}authentication: userPolicy.Create,{{/if}}
15
+ prismaArgs: {
16
+ omit: { password: true },
17
+ },
18
+ });
19
+
20
+ userRouteHook.findOne({
21
+ {{#if (neq authentication.type "none")}}authentication: userPolicy.View,{{/if}}
22
+ prismaArgs: {
23
+ omit: { password: true },
24
+ {{#if (eq authentication.type "dynamic")}}
25
+ include: {
26
+ {{#if authentication.multipleRoles}}
27
+ roles: {
28
+ include: {
29
+ role: {
30
+ include: {
31
+ permissions: true,
32
+ },
33
+ },
34
+ },
35
+ },
36
+ {{else}}
37
+ role: {
38
+ include: {
39
+ role: {
40
+ include: {
41
+ permissions: true,
42
+ },
43
+ },
44
+ },
45
+ },
46
+ {{/if}}
47
+ },
48
+ {{/if}}
49
+ },
50
+ });
51
+
52
+ userRouteHook.findMany({
53
+ {{#if (neq authentication.type "none")}}authentication: userPolicy.View,{{/if}}
54
+ prismaArgs: {
55
+ omit: { password: true },
56
+ {{#if (eq authentication.type "dynamic")}}
57
+ include: {
58
+ {{#if authentication.multipleRoles}}
59
+ roles: {
60
+ include: {
61
+ role: true,
62
+ },
63
+ },
64
+ {{else}}
65
+ role: {
66
+ include: {
67
+ role: true,
68
+ },
69
+ },
70
+ {{/if}}
71
+ },
72
+ {{/if}}
73
+ },
74
+ });
75
+
76
+ userRouteHook.updateOne({
77
+ {{#if validation.type}}validation: { body: UpdateUserDto },{{/if}}
78
+ {{#if (neq authentication.type "none")}}authentication: userPolicy.Update,{{/if}}
79
+ prismaArgs: {
80
+ omit: { password: true },
81
+ },
82
+ });
83
+
84
+ userRouteHook.deleteOne({
85
+ {{#if (neq authentication.type "none")}}authentication: userPolicy.Delete,{{/if}}
86
+ });
87
+
88
+ const userRouter = ArkosRouter({
89
+ prefix: "/users",
90
+ openapi: { tags: ["Users"] },
91
+ });
5
92
 
6
- const userRouter = ArkosRouter({
7
- prefix: "/users",
8
- openapi: { tags: ["Users"] }
9
- });
93
+ userRouter.load(userRouteHook);
10
94
 
11
95
  export default userRouter;