create-warlock 4.0.5 → 4.0.28

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 (66) hide show
  1. package/package.json +1 -1
  2. package/templates/warlock/.prettierignore +4 -0
  3. package/templates/warlock/.prettierrc +8 -0
  4. package/templates/warlock/.prettierrc.json +11 -11
  5. package/templates/warlock/eslint.config.js +98 -0
  6. package/templates/warlock/package.json +0 -67
  7. package/templates/warlock/warlock.config.ts +2 -2
  8. package/templates/warlock/.eslintrc.json +0 -44
  9. package/templates/warlock/eslint.config.mjs +0 -76
  10. package/templates/warlock/src/app/main.ts +0 -12
  11. package/templates/warlock/src/app/posts/controllers/create-post.controller.ts +0 -22
  12. package/templates/warlock/src/app/posts/controllers/get-all-posts.controller.ts +0 -13
  13. package/templates/warlock/src/app/posts/controllers/get-post.controller.ts +0 -28
  14. package/templates/warlock/src/app/posts/models/index.ts +0 -1
  15. package/templates/warlock/src/app/posts/models/post/index.ts +0 -1
  16. package/templates/warlock/src/app/posts/models/post/post.model.ts +0 -32
  17. package/templates/warlock/src/app/posts/output/post.output.ts +0 -12
  18. package/templates/warlock/src/app/posts/repositories/posts.repository.ts +0 -26
  19. package/templates/warlock/src/app/posts/routes.ts +0 -12
  20. package/templates/warlock/src/app/posts/services/posts.service.ts +0 -28
  21. package/templates/warlock/src/app/posts/types/index.ts +0 -6
  22. package/templates/warlock/src/app/posts/utils/locales.ts +0 -8
  23. package/templates/warlock/src/app/posts/validation/create-post.validation.ts +0 -8
  24. package/templates/warlock/src/app/posts/validation/get-post.validation.ts +0 -7
  25. package/templates/warlock/src/app/users/controllers/auth/activate-account.controller.ts +0 -49
  26. package/templates/warlock/src/app/users/controllers/auth/admin-login.controller.ts +0 -39
  27. package/templates/warlock/src/app/users/controllers/auth/create-account-simple.controller.ts +0 -23
  28. package/templates/warlock/src/app/users/controllers/auth/create-account.controller.ts +0 -23
  29. package/templates/warlock/src/app/users/controllers/auth/forget-password.controller.ts +0 -39
  30. package/templates/warlock/src/app/users/controllers/auth/login.controller.ts +0 -32
  31. package/templates/warlock/src/app/users/controllers/auth/logout.controller.ts +0 -10
  32. package/templates/warlock/src/app/users/controllers/auth/resend-activation-code.controller.ts +0 -45
  33. package/templates/warlock/src/app/users/controllers/auth/reset-password.controller.ts +0 -43
  34. package/templates/warlock/src/app/users/controllers/auth/verify-forget-password-code.controller.ts +0 -18
  35. package/templates/warlock/src/app/users/controllers/profile/change-password.controller.ts +0 -31
  36. package/templates/warlock/src/app/users/controllers/profile/my-profile.controller.ts +0 -10
  37. package/templates/warlock/src/app/users/controllers/profile/update-profile.controller.ts +0 -25
  38. package/templates/warlock/src/app/users/controllers/users.restful.ts +0 -26
  39. package/templates/warlock/src/app/users/events/attach-user-to-response.ts +0 -18
  40. package/templates/warlock/src/app/users/events/register-current-user-to-model-authors.ts +0 -28
  41. package/templates/warlock/src/app/users/events/update-authors.ts +0 -19
  42. package/templates/warlock/src/app/users/mail/send-forget-password-email.ts +0 -20
  43. package/templates/warlock/src/app/users/models/user/index.ts +0 -1
  44. package/templates/warlock/src/app/users/models/user/migrations/20-10-2024_07-59-54-user.migration.ts +0 -15
  45. package/templates/warlock/src/app/users/models/user/user.model.ts +0 -59
  46. package/templates/warlock/src/app/users/output/user.output.ts +0 -12
  47. package/templates/warlock/src/app/users/repositories/users.repository.ts +0 -27
  48. package/templates/warlock/src/app/users/routes.ts +0 -51
  49. package/templates/warlock/src/app/users/services/create-account.service.ts +0 -16
  50. package/templates/warlock/src/app/users/services/login.service.ts +0 -16
  51. package/templates/warlock/src/app/users/utils/locales.ts +0 -16
  52. package/templates/warlock/src/app/users/validation/activate-account.validation.ts +0 -8
  53. package/templates/warlock/src/app/users/validation/admin-login.validation.ts +0 -8
  54. package/templates/warlock/src/app/users/validation/create-account.validation.ts +0 -10
  55. package/templates/warlock/src/app/users/validation/login.validation.ts +0 -8
  56. package/templates/warlock/src/app/utils/output.ts +0 -17
  57. package/templates/warlock/src/app/utils/router.ts +0 -104
  58. package/templates/warlock/src/config/app.ts +0 -12
  59. package/templates/warlock/src/config/auth.ts +0 -16
  60. package/templates/warlock/src/config/cache.ts +0 -40
  61. package/templates/warlock/src/config/database.ts +0 -18
  62. package/templates/warlock/src/config/http.ts +0 -22
  63. package/templates/warlock/src/config/log.ts +0 -19
  64. package/templates/warlock/src/config/mail.ts +0 -16
  65. package/templates/warlock/src/config/uploads.ts +0 -12
  66. package/templates/warlock/src/config/validation.ts +0 -78
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-warlock",
3
- "version": "4.0.5",
3
+ "version": "4.0.28",
4
4
  "main": "./esm/index.js",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -0,0 +1,4 @@
1
+ node_modules
2
+ dist
3
+
4
+
@@ -0,0 +1,8 @@
1
+ {
2
+ "semi": true,
3
+ "singleQuote": false,
4
+ "trailingComma": "all",
5
+ "printWidth": 100,
6
+ "plugins": ["prettier-plugin-organize-imports"]
7
+ }
8
+
@@ -1,11 +1,11 @@
1
- {
2
- "semi": true,
3
- "tabWidth": 2,
4
- "printWidth": 80,
5
- "singleQuote": false,
6
- "arrowParens": "avoid",
7
- "trailingComma": "all",
8
- "bracketSameLine": true,
9
- "endOfLine": "auto",
10
- "plugins": ["prettier-plugin-organize-imports"]
11
- }
1
+ {
2
+ "semi": true,
3
+ "tabWidth": 2,
4
+ "printWidth": 80,
5
+ "singleQuote": false,
6
+ "arrowParens": "avoid",
7
+ "trailingComma": "all",
8
+ "bracketSameLine": true,
9
+ "endOfLine": "lf",
10
+ "plugins": ["prettier-plugin-organize-imports"]
11
+ }
@@ -0,0 +1,98 @@
1
+ import tsParser from "@typescript-eslint/parser";
2
+ import tsPlugin from "@typescript-eslint/eslint-plugin";
3
+ import prettierPlugin from "eslint-plugin-prettier";
4
+ import prettierConfig from "eslint-config-prettier";
5
+ import unusedImports from "eslint-plugin-unused-imports";
6
+
7
+ export default [
8
+ // Global configuration
9
+ {
10
+ languageOptions: {
11
+ ecmaVersion: "latest",
12
+ sourceType: "module",
13
+ globals: {
14
+ // Node.js globals
15
+ console: "readonly",
16
+ process: "readonly",
17
+ Buffer: "readonly",
18
+ __dirname: "readonly",
19
+ __filename: "readonly",
20
+ global: "readonly",
21
+ module: "readonly",
22
+ require: "readonly",
23
+ exports: "readonly",
24
+ // ES2021 globals
25
+ Promise: "readonly",
26
+ // Jest globals
27
+ describe: "readonly",
28
+ it: "readonly",
29
+ test: "readonly",
30
+ expect: "readonly",
31
+ beforeEach: "readonly",
32
+ afterEach: "readonly",
33
+ beforeAll: "readonly",
34
+ afterAll: "readonly",
35
+ jest: "readonly",
36
+ },
37
+ },
38
+ },
39
+
40
+ // TypeScript files configuration
41
+ {
42
+ files: ["**/*.ts", "**/*.tsx"],
43
+ languageOptions: {
44
+ parser: tsParser,
45
+ parserOptions: {
46
+ ecmaVersion: "latest",
47
+ sourceType: "module",
48
+ },
49
+ },
50
+ plugins: {
51
+ "@typescript-eslint": tsPlugin,
52
+ prettier: prettierPlugin,
53
+ "unused-imports": unusedImports,
54
+ },
55
+ rules: {
56
+ // Prettier integration
57
+ ...prettierConfig.rules,
58
+ "prettier/prettier": "error",
59
+
60
+ // TypeScript rules
61
+ "@typescript-eslint/no-explicit-any": "off",
62
+ "@typescript-eslint/no-unused-vars": "off",
63
+ "no-unused-vars": "off",
64
+ "unused-imports/no-unused-vars": [
65
+ "warn",
66
+ {
67
+ vars: "all",
68
+ varsIgnorePattern: "^_",
69
+ args: "after-used",
70
+ argsIgnorePattern: "^_",
71
+ },
72
+ ],
73
+ "unused-imports/no-unused-imports": "error",
74
+ "@typescript-eslint/explicit-member-accessibility": [
75
+ "error",
76
+ { accessibility: "explicit" },
77
+ ],
78
+ "@typescript-eslint/consistent-type-imports": [
79
+ "error",
80
+ {
81
+ prefer: "type-imports",
82
+ disallowTypeAnnotations: false,
83
+ },
84
+ ],
85
+ },
86
+ },
87
+
88
+ // Ignore patterns
89
+ {
90
+ ignores: [
91
+ "dist/",
92
+ "node_modules/",
93
+ "**/*.js",
94
+ "!**/*.config.js",
95
+ "!eslint.config.js",
96
+ ],
97
+ },
98
+ ];
@@ -1,67 +0,0 @@
1
- {
2
- "name": "app-name",
3
- "version": "1.0.0",
4
- "private": true,
5
- "type": "module",
6
- "scripts": {
7
- "dev": "warlock dev",
8
- "build": "tsc && warlock build",
9
- "prod": "warlock start",
10
- "postman": "warlock postman",
11
- "migrate": "warlock migrate",
12
- "migrate.fresh": "warlock migrate --fresh",
13
- "migrate.list": "warlock migrate --list",
14
- "jwt": "warlock jwt.generate",
15
- "test": "warlock test.init && vitest",
16
- "prod.start": "yarn build && yarn prod",
17
- "serve": "yarn build && nohup warlock start > /dev/null 2>&1",
18
- "lint": "npx eslint --fix ./src --max-warnings=0",
19
- "format": "npx prettier --write ./src/**/*.{js,jsx,ts,tsx,css,md,json} --config ./.prettierrc.json",
20
- "tsc": "npx tsc --noEmit",
21
- "prepare": "huskier-init && husky install",
22
- "lf": "find . -type d ( -name 'node_modules' -o -name '.git' ) -prune -o -type f -exec dos2unix {} ;"
23
- },
24
- "dependencies": {
25
- "@mongez/collection": "^1.2.0",
26
- "@mongez/encryption": "^1.0.4",
27
- "@mongez/fs": "^3.0.5",
28
- "@mongez/reinforcements": "^2.3.10",
29
- "@mongez/localization": "^3.0.0",
30
- "@mongez/dotenv": "^1.1.9",
31
- "@mongez/config": "^1.0.26",
32
- "@mongez/supportive-is": "^2.0.4",
33
- "@warlock.js/auth": "4.0.5",
34
- "@warlock.js/cache": "4.0.5",
35
- "@warlock.js/cascade": "4.0.5",
36
- "@warlock.js/core": "4.0.5",
37
- "@warlock.js/logger": "4.0.5",
38
- "@warlock.js/seal": "4.0.5",
39
- "@faker-js/faker": "^9.2.0",
40
- "dayjs": "^1.11.13"
41
- },
42
- "devDependencies": {
43
- "eslint": "^9.13.0",
44
- "@types/react": "^18.3.11",
45
- "@typescript-eslint/eslint-plugin": "^8.10.0",
46
- "@typescript-eslint/parser": "^8.10.0",
47
- "eslint-config-prettier": "^9.1.0",
48
- "eslint-plugin-prettier": "^5.2.1",
49
- "eslint-plugin-unused-imports": "^4.1.4",
50
- "@mongez/huskier": "^3.0.0",
51
- "prettier": "^3.3.3",
52
- "prettier-plugin-organize-imports": "^4.1.0",
53
- "typescript": "^5.6.3",
54
- "vite": "^5.4.9",
55
- "vitest": "^2.1.3",
56
- "husky": "^8.0.0"
57
- },
58
- "huskier": {
59
- "hooks": {
60
- "pre-commit": [
61
- "yarn format",
62
- "yarn lint",
63
- "yarn tsc"
64
- ]
65
- }
66
- }
67
- }
@@ -1,8 +1,8 @@
1
- import { registerJWTSecretGeneratorCommand } from "@warlock.js/auth";
1
+ import { registerAuthCleanupCommand, registerJWTSecretGeneratorCommand } from "@warlock.js/auth";
2
2
  import { defineConfig } from "@warlock.js/core";
3
3
 
4
4
  export default defineConfig({
5
5
  cli: {
6
- commands: [registerJWTSecretGeneratorCommand()],
6
+ commands: [registerJWTSecretGeneratorCommand(), registerAuthCleanupCommand()],
7
7
  },
8
8
  });
@@ -1,44 +0,0 @@
1
- {
2
- "env": {
3
- "node": true,
4
- "es2021": true,
5
- "jest": true
6
- },
7
- "extends": [
8
- "eslint:recommended",
9
- "plugin:@typescript-eslint/recommended",
10
- "plugin:prettier/recommended"
11
- ],
12
- "parser": "@typescript-eslint/parser",
13
- "parserOptions": {
14
- "ecmaVersion": "latest",
15
- "sourceType": "module"
16
- },
17
- "plugins": ["@typescript-eslint", "prettier", "unused-imports"],
18
- "rules": {
19
- "@typescript-eslint/no-explicit-any": "off",
20
- "@typescript-eslint/no-unused-vars": "off",
21
- "no-unused-vars": "off",
22
- "unused-imports/no-unused-vars": [
23
- "warn",
24
- {
25
- "vars": "all",
26
- "varsIgnorePattern": "^_",
27
- "args": "after-used",
28
- "argsIgnorePattern": "^_"
29
- }
30
- ],
31
- "unused-imports/no-unused-imports": "error",
32
- "@typescript-eslint/explicit-member-accessibility": [
33
- "error",
34
- { "accessibility": "explicit" }
35
- ],
36
- "@typescript-eslint/consistent-type-imports": [
37
- "error",
38
- {
39
- "prefer": "type-imports",
40
- "disallowTypeAnnotations": false
41
- }
42
- ]
43
- }
44
- }
@@ -1,76 +0,0 @@
1
- import { FlatCompat } from "@eslint/eslintrc";
2
- import js from "@eslint/js";
3
- import typescriptEslint from "@typescript-eslint/eslint-plugin";
4
- import tsParser from "@typescript-eslint/parser";
5
- import prettier from "eslint-plugin-prettier";
6
- import unusedImports from "eslint-plugin-unused-imports";
7
- import globals from "globals";
8
- import path from "node:path";
9
- import { fileURLToPath } from "node:url";
10
-
11
- const __filename = fileURLToPath(import.meta.url);
12
- const __dirname = path.dirname(__filename);
13
- const compat = new FlatCompat({
14
- baseDirectory: __dirname,
15
- recommendedConfig: js.configs.recommended,
16
- allConfig: js.configs.all,
17
- });
18
-
19
- export default [
20
- ...compat.extends(
21
- "eslint:recommended",
22
- "plugin:@typescript-eslint/recommended",
23
- "plugin:prettier/recommended",
24
- ),
25
- {
26
- plugins: {
27
- "@typescript-eslint": typescriptEslint,
28
- prettier,
29
- "unused-imports": unusedImports,
30
- },
31
-
32
- languageOptions: {
33
- globals: {
34
- ...globals.node,
35
- ...globals.jest,
36
- },
37
-
38
- parser: tsParser,
39
- ecmaVersion: "latest",
40
- sourceType: "module",
41
- },
42
-
43
- rules: {
44
- "@typescript-eslint/no-explicit-any": "off",
45
- "@typescript-eslint/no-unused-vars": "off",
46
- "no-unused-vars": "off",
47
-
48
- "unused-imports/no-unused-vars": [
49
- "warn",
50
- {
51
- vars: "all",
52
- varsIgnorePattern: "^_",
53
- args: "after-used",
54
- argsIgnorePattern: "^_",
55
- },
56
- ],
57
-
58
- "unused-imports/no-unused-imports": "error",
59
-
60
- "@typescript-eslint/explicit-member-accessibility": [
61
- "error",
62
- {
63
- accessibility: "explicit",
64
- },
65
- ],
66
-
67
- "@typescript-eslint/consistent-type-imports": [
68
- "error",
69
- {
70
- prefer: "type-imports",
71
- disallowTypeAnnotations: false,
72
- },
73
- ],
74
- },
75
- },
76
- ];
@@ -1,12 +0,0 @@
1
- // this file is called before any main file in the other modules
2
- // This will be called directly when the app starts
3
- import { onceConnected } from "@warlock.js/cascade";
4
-
5
- // This function will be called once the app is connected to the database
6
- // it will be called on app start
7
- // If the app is running in development mode, this function will be called
8
- // every time a file is changed
9
- // it could be useful to test some code or do small database modifications
10
- onceConnected(async () => {
11
- //
12
- });
@@ -1,22 +0,0 @@
1
- import type { Request, RequestHandler, Response } from "@warlock.js/core";
2
- import type { Post } from "app/posts/models/post";
3
- import { createPostService } from "app/posts/services/posts.service";
4
- import {
5
- createPostSchema,
6
- type CreatePostData,
7
- } from "app/posts/validation/create-post.validation";
8
-
9
- export const createPostController: RequestHandler = async (
10
- request: Request<Post, CreatePostData>,
11
- response: Response,
12
- ) => {
13
- const post = await createPostService(request.validated());
14
-
15
- return response.success({
16
- post,
17
- });
18
- };
19
-
20
- createPostController.validation = {
21
- schema: createPostSchema,
22
- };
@@ -1,13 +0,0 @@
1
- import type { RequestHandler, Response } from "@warlock.js/core";
2
- import { getAllPostsService } from "app/posts/services/posts.service";
3
-
4
- export const getAllPostsController: RequestHandler = async (
5
- request,
6
- response: Response,
7
- ) => {
8
- const posts = await getAllPostsService();
9
-
10
- return response.success({
11
- posts,
12
- });
13
- };
@@ -1,28 +0,0 @@
1
- import type { Request, RequestHandler, Response } from "@warlock.js/core";
2
- import type { Post } from "app/posts/models/post";
3
- import { getPostByIdService } from "app/posts/services/posts.service";
4
- import {
5
- getPostSchema,
6
- type GetPostData,
7
- } from "app/posts/validation/get-post.validation";
8
-
9
- export const getPostController: RequestHandler = async (
10
- request: Request<Post, GetPostData>,
11
- response: Response,
12
- ) => {
13
- const post = await getPostByIdService(request.int("id"));
14
-
15
- if (!post) {
16
- return response.notFound({
17
- error: "Post Not found",
18
- });
19
- }
20
-
21
- return response.success({
22
- post,
23
- });
24
- };
25
-
26
- getPostController.validation = {
27
- schema: getPostSchema,
28
- };
@@ -1 +0,0 @@
1
- export * from "./post";
@@ -1 +0,0 @@
1
- export * from "./post.model";
@@ -1,32 +0,0 @@
1
- import { Model, type Casts } from "@warlock.js/cascade";
2
- import { PostOutput } from "../../output/post.output";
3
-
4
- export class Post extends Model {
5
- /**
6
- * Collection name
7
- */
8
- public static collection = "posts";
9
-
10
- /**
11
- * Output
12
- */
13
- public static output = PostOutput;
14
-
15
- /**
16
- * {@inheritDoc}
17
- */
18
- public syncWith = [];
19
-
20
- /**
21
- * Casts
22
- */
23
- protected casts: Casts = {
24
- title: "string",
25
- content: "string",
26
- };
27
-
28
- /**
29
- * {@inheritDoc}
30
- */
31
- public embedded = ["id", "title"];
32
- }
@@ -1,12 +0,0 @@
1
- import { Output, type FinalOutput } from "@warlock.js/core";
2
- import { withBaseOutputDetails } from "app/utils/output";
3
-
4
- export class PostOutput extends Output {
5
- /**
6
- * {@inheritdoc}
7
- */
8
- protected output: FinalOutput = withBaseOutputDetails({
9
- title: "string",
10
- content: "string",
11
- });
12
- }
@@ -1,26 +0,0 @@
1
- import type { FilterByOptions, RepositoryOptions } from "@warlock.js/core";
2
- import { RepositoryManager } from "@warlock.js/core";
3
-
4
- import { Post } from "../models/post";
5
-
6
- export class PostsRepository extends RepositoryManager<Post> {
7
- /**
8
- * {@inheritDoc}
9
- */
10
- public model = Post;
11
-
12
- /**
13
- * List default options
14
- */
15
- protected defaultOptions: RepositoryOptions = this.withDefaultOptions({});
16
-
17
- /**
18
- * Filter By options
19
- */
20
- protected filterBy: FilterByOptions = this.withDefaultFilters({
21
- title: "like",
22
- author: ["int", "createdBy.id"],
23
- });
24
- }
25
-
26
- export const postsRepository = new PostsRepository();
@@ -1,12 +0,0 @@
1
- import { router } from "@warlock.js/core";
2
- import { guarded } from "app/utils/router";
3
- import { createPostController } from "./controllers/create-post.controller";
4
- import { getAllPostsController } from "./controllers/get-all-posts.controller";
5
- import { getPostController } from "./controllers/get-post.controller";
6
-
7
- router.get("/posts", getAllPostsController);
8
- router.get("/posts/:id", getPostController);
9
-
10
- guarded(() => {
11
- router.post("/posts", createPostController);
12
- });
@@ -1,28 +0,0 @@
1
- import type { PaginationListing } from "@warlock.js/cascade";
2
- import type { Post } from "app/posts/models/post";
3
- import { postsRepository } from "app/posts/repositories/posts.repository";
4
- import type { CreatePostData } from "app/posts/validation/create-post.validation";
5
- import type { PostsListsParams } from "../types";
6
-
7
- /**
8
- * Create a new post
9
- */
10
- export async function createPostService(data: CreatePostData): Promise<Post> {
11
- return await postsRepository.create(data);
12
- }
13
-
14
- /**
15
- * Get all posts
16
- */
17
- export async function getAllPostsService(
18
- params: PostsListsParams = {},
19
- ): Promise<PaginationListing<Post>> {
20
- return await postsRepository.list(params);
21
- }
22
-
23
- /**
24
- * Get a single post by ID
25
- */
26
- export async function getPostByIdService(id: number): Promise<Post | null> {
27
- return await postsRepository.findActiveCached(id);
28
- }
@@ -1,6 +0,0 @@
1
- export type PostsListsParams = {
2
- page?: number;
3
- limit?: number;
4
- author?: number; // author id
5
- title?: string;
6
- };
@@ -1,8 +0,0 @@
1
- import { groupedTranslations } from "@mongez/localization";
2
-
3
- groupedTranslations("posts", {
4
- postNotFound: {
5
- en: "Post Not found",
6
- ar: "المنشور غير موجود",
7
- },
8
- });
@@ -1,8 +0,0 @@
1
- import { v, type Infer } from "@warlock.js/core";
2
-
3
- export const createPostSchema = v.object({
4
- title: v.string().required().minLength(4),
5
- content: v.string().required(),
6
- });
7
-
8
- export type CreatePostData = Infer<typeof createPostSchema>;
@@ -1,7 +0,0 @@
1
- import { v, type Infer } from "@warlock.js/core";
2
-
3
- export const getPostSchema = v.object({
4
- id: v.int().required(),
5
- });
6
-
7
- export type GetPostData = Infer<typeof getPostSchema>;
@@ -1,49 +0,0 @@
1
- import type { Request, Response } from "@warlock.js/core";
2
- import { usersRepository } from "app/users/repositories/users.repository";
3
- import { loginUserService } from "app/users/services/login.service";
4
- import {
5
- activateAccountSchema,
6
- type ActivateAccountData,
7
- } from "app/users/validation/activate-account.validation";
8
-
9
- export default async function activateAccountController(
10
- request: Request<ActivateAccountData>,
11
- response: Response,
12
- ) {
13
- const currentUser = request.user;
14
-
15
- currentUser.unset("codeExpiresAt", "activationCode");
16
-
17
- currentUser.save({
18
- isActive: true,
19
- activatedAt: new Date(),
20
- });
21
-
22
- const loginData = await loginUserService(currentUser);
23
-
24
- return response.success(loginData);
25
- }
26
-
27
- activateAccountController.validation = {
28
- schema: activateAccountSchema,
29
- validate: async (request: Request, response: Response) => {
30
- const user = await usersRepository.first({
31
- email: request.input("email"),
32
- activationCode: request.int("code"),
33
- });
34
-
35
- if (!user) {
36
- return response.notFound({
37
- error: "Invalid activation code",
38
- });
39
- }
40
-
41
- if (user.isActive) {
42
- return response.badRequest({
43
- error: "User already activated",
44
- });
45
- }
46
-
47
- request.user = user;
48
- },
49
- };
@@ -1,39 +0,0 @@
1
- import type { Request, Response } from "@warlock.js/core";
2
- import { User } from "app/users/models/user";
3
- import { loginUserService } from "app/users/services/login.service";
4
- import {
5
- adminLoginSchema,
6
- type AdminLoginData,
7
- } from "app/users/validation/admin-login.validation";
8
-
9
- export default async function adminLoginController(
10
- request: Request<AdminLoginData>,
11
- response: Response,
12
- ) {
13
- const user = request.user;
14
-
15
- const loginData = await loginUserService(user);
16
-
17
- return response.success(loginData);
18
- }
19
-
20
- adminLoginController.validation = {
21
- schema: adminLoginSchema,
22
- validate: async (request: Request, response: Response) => {
23
- const user = await User.attempt(request.validated());
24
-
25
- if (!user) {
26
- return response.badRequest({
27
- error: "Invalid credentials",
28
- });
29
- }
30
-
31
- if (!user.get("isActive")) {
32
- return response.badRequest({
33
- error: "Your account is suspended!",
34
- });
35
- }
36
-
37
- request.user = user;
38
- },
39
- };