create-craftjs 1.0.16 → 2.0.1
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.
- package/README.md +21 -14
- package/bin/index.js +3 -3
- package/package.json +1 -1
- package/template/craft/commands/build.js +3 -1
- package/template/craft.js +36 -35
- package/template/package-lock.json +267 -2
- package/template/package.json +2 -1
- package/template/src/config/cloudinary.ts +2 -2
- package/template/src/config/database.ts +3 -3
- package/template/src/config/nodemailer.ts +2 -2
- package/template/src/config/web.ts +6 -6
- package/template/src/controllers/auth-controller.ts +5 -5
- package/template/src/controllers/user-controller.ts +5 -5
- package/template/src/middleware/auth-middleware.ts +6 -6
- package/template/src/middleware/error-middleware.ts +2 -2
- package/template/src/middleware/http-logger-middleware.ts +1 -1
- package/template/src/repositories/auth-token-repository.ts +1 -1
- package/template/src/repositories/user-repository.ts +1 -1
- package/template/src/routes/auth-route.ts +2 -2
- package/template/src/routes/main-route.ts +3 -4
- package/template/src/routes/user-route.ts +2 -3
- package/template/src/services/auth-service.ts +10 -10
- package/template/src/services/user-service.ts +7 -7
- package/template/src/utils/cookieEncrypt.ts +1 -2
- package/template/src/utils/formatTime.ts +1 -1
- package/template/src/utils/swagger.ts +1 -1
- package/template/test/user.test.ts +2 -2
- package/template/tsconfig.json +18 -1
- /package/template/craft/commands/{docker-build.js → build-docker.js} +0 -0
- /package/template/src/{types → utils}/type-request.ts +0 -0
package/README.md
CHANGED
|
@@ -63,6 +63,7 @@ npm install
|
|
|
63
63
|
node craft key:generate
|
|
64
64
|
node craft db:generate
|
|
65
65
|
node craft db:migrate
|
|
66
|
+
node craft db:seed
|
|
66
67
|
node craft dev
|
|
67
68
|
```
|
|
68
69
|
|
|
@@ -79,32 +80,36 @@ node craft help
|
|
|
79
80
|
```
|
|
80
81
|
my-app/
|
|
81
82
|
├── craft/
|
|
83
|
+
├── logs/
|
|
84
|
+
├── prisma/
|
|
85
|
+
├── public/
|
|
82
86
|
├── src/
|
|
83
87
|
│ ├── apidocs/
|
|
84
88
|
│ ├── config/
|
|
85
89
|
│ ├── controllers/
|
|
90
|
+
│ ├── dtos/
|
|
86
91
|
│ ├── middleware/
|
|
87
92
|
│ ├── repositories/
|
|
88
|
-
│ ├── dtos/
|
|
89
93
|
│ ├── routes/
|
|
90
94
|
│ └── services/
|
|
91
|
-
│ └── types/
|
|
92
95
|
│ └── utils/
|
|
93
96
|
│ └── validations/
|
|
97
|
+
│ └── views/
|
|
94
98
|
│ └── main.ts
|
|
99
|
+
├── temp/
|
|
95
100
|
├── test/
|
|
96
|
-
├── logs/
|
|
97
|
-
├── docker-compose.yml
|
|
98
|
-
├── Dockerfile
|
|
99
101
|
├── .env
|
|
100
102
|
├── .env.example
|
|
101
|
-
├── prisma/
|
|
102
103
|
├── .gitignore
|
|
103
104
|
├── babel.config.json
|
|
104
105
|
├── craft.js
|
|
106
|
+
├── docker-compose.yml
|
|
107
|
+
├── Dockerfile
|
|
105
108
|
├── nodemon.json
|
|
106
|
-
├── package.json
|
|
107
109
|
├── package-lock.json
|
|
110
|
+
├── package.json
|
|
111
|
+
├── prisma.config.ts
|
|
112
|
+
├── README.md
|
|
108
113
|
└── tsconfig.json
|
|
109
114
|
```
|
|
110
115
|
|
|
@@ -114,26 +119,28 @@ my-app/
|
|
|
114
119
|
|
|
115
120
|
| Command | Description |
|
|
116
121
|
| ----------------------- | ------------------------------ |
|
|
117
|
-
| `craft start` | Start production server |
|
|
118
|
-
| `craft dev` | Run in development mode |
|
|
119
|
-
| `craft build` | Build for production |
|
|
120
122
|
| `craft build:docker` | Deploy Docker for production |
|
|
121
|
-
| `craft
|
|
123
|
+
| `craft build` | Build for production |
|
|
124
|
+
| `craft db:fresh` | Run Prisma migrate reset |
|
|
122
125
|
| `craft db:generate` | Generate Prisma client |
|
|
123
126
|
| `craft db:migrate` | Run Prisma migrations |
|
|
124
|
-
| `craft db:
|
|
127
|
+
| `craft db:seed` | Run Prisma Seeder |
|
|
128
|
+
| `craft dev` | Run in development mode |
|
|
125
129
|
| `craft key:generate` | Generate secret keys |
|
|
126
|
-
| `craft make:
|
|
130
|
+
| `craft make:apidocs` | Make Apidocs File |
|
|
127
131
|
| `craft make:command` | Make Command File |
|
|
132
|
+
| `craft make:controller` | Make Controller File |
|
|
133
|
+
| `craft make:dto` | Make Data Transfer Object File |
|
|
128
134
|
| `craft make:middleware` | Make Middleware File |
|
|
129
135
|
| `craft make:repository` | Make repository File |
|
|
130
|
-
| `craft make:dto` | Make Data Transfer Object File |
|
|
131
136
|
| `craft make:route` | Make Route File |
|
|
132
137
|
| `craft make:service` | Make Service File |
|
|
133
138
|
| `craft make:test` | Make Test case |
|
|
134
139
|
| `craft make:utils` | Make Utils |
|
|
135
140
|
| `craft make:validation` | Make Validation |
|
|
136
141
|
| `craft make:view` | Make View |
|
|
142
|
+
| `craft start` | Start production server |
|
|
143
|
+
| `craft test` | Run Jest tests |
|
|
137
144
|
|
|
138
145
|
---
|
|
139
146
|
|
package/bin/index.js
CHANGED
|
@@ -151,20 +151,20 @@ logs
|
|
|
151
151
|
console.warn("⚠️ npm install failed.");
|
|
152
152
|
console.log("\n✅ Done!");
|
|
153
153
|
console.log(
|
|
154
|
-
`\nNext steps:\n cd ${projectName}\n npm install\n node craft key:generate\n node craft db:generate\n node craft db:migrate\n node craft dev`
|
|
154
|
+
`\nNext steps:\n cd ${projectName}\n npm install\n node craft key:generate\n node craft db:generate\n node craft db:migrate\n node craft db:seed\n node craft dev`
|
|
155
155
|
);
|
|
156
156
|
} else {
|
|
157
157
|
console.log("✅ Dependencies installed successfully.");
|
|
158
158
|
console.log("\n✅ Done!");
|
|
159
159
|
console.log(
|
|
160
|
-
`\nNext steps:\n cd ${projectName}\n node craft key:generate\n node craft db:generate\n node craft db:migrate\n node craft dev`
|
|
160
|
+
`\nNext steps:\n cd ${projectName}\n node craft key:generate\n node craft db:generate\n node craft db:migrate\n node craft db:seed\n node craft dev`
|
|
161
161
|
);
|
|
162
162
|
}
|
|
163
163
|
} else {
|
|
164
164
|
console.log("ℹ️ Skipping dependency installation.");
|
|
165
165
|
console.log("\n✅ Done!");
|
|
166
166
|
console.log(
|
|
167
|
-
`\nNext steps:\n cd ${projectName}\n npm install\n node craft key:generate\n node craft db:generate\n node craft db:migrate\n node craft dev`
|
|
167
|
+
`\nNext steps:\n cd ${projectName}\n npm install\n node craft key:generate\n node craft db:generate\n node craft db:migrate\n node craft db:seed\n node craft dev`
|
|
168
168
|
);
|
|
169
169
|
}
|
|
170
170
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-craftjs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "A starter kit backend framework powered by Express, TypeScript, EJS Engine, and Prisma — designed for rapid development, simplicity, and scalability.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"create-craftjs": "bin/index.js"
|
|
@@ -4,7 +4,9 @@ function Build() {
|
|
|
4
4
|
console.log(chalk.blue("📦 Building project..."));
|
|
5
5
|
|
|
6
6
|
try {
|
|
7
|
-
execSync("npx tsc && cp -r src/views build/views", {
|
|
7
|
+
execSync("npx tsc && tsc-alias && cp -r src/views build/views", {
|
|
8
|
+
stdio: "inherit",
|
|
9
|
+
});
|
|
8
10
|
execSync("cp -r public build/public", { stdio: "inherit" });
|
|
9
11
|
console.log(chalk.green("✅ Build completed successfully."));
|
|
10
12
|
} catch (error) {
|
package/template/craft.js
CHANGED
|
@@ -4,6 +4,15 @@ const yargs = require("yargs");
|
|
|
4
4
|
const { hideBin } = require("yargs/helpers");
|
|
5
5
|
|
|
6
6
|
yargs(hideBin(process.argv))
|
|
7
|
+
.command(
|
|
8
|
+
"build:docker",
|
|
9
|
+
"Docker build for production",
|
|
10
|
+
() => {},
|
|
11
|
+
() => {
|
|
12
|
+
const start = require("./craft/commands/build-docker.js");
|
|
13
|
+
start();
|
|
14
|
+
}
|
|
15
|
+
)
|
|
7
16
|
.command(
|
|
8
17
|
"build",
|
|
9
18
|
"Building project to production ",
|
|
@@ -14,20 +23,20 @@ yargs(hideBin(process.argv))
|
|
|
14
23
|
}
|
|
15
24
|
)
|
|
16
25
|
.command(
|
|
17
|
-
"db:
|
|
18
|
-
"Running prisma
|
|
26
|
+
"db:fresh",
|
|
27
|
+
"Running prisma migrate fresh",
|
|
19
28
|
() => {},
|
|
20
29
|
() => {
|
|
21
|
-
const
|
|
22
|
-
|
|
30
|
+
const dbfresh = require("./craft/commands/db-fresh.js");
|
|
31
|
+
dbfresh();
|
|
23
32
|
}
|
|
24
33
|
)
|
|
25
34
|
.command(
|
|
26
|
-
"db:
|
|
27
|
-
"Running prisma
|
|
35
|
+
"db:generate",
|
|
36
|
+
"Running prisma generate",
|
|
28
37
|
() => {},
|
|
29
38
|
() => {
|
|
30
|
-
const dbgenerate = require("./craft/commands/db-
|
|
39
|
+
const dbgenerate = require("./craft/commands/db-generate.js");
|
|
31
40
|
dbgenerate();
|
|
32
41
|
}
|
|
33
42
|
)
|
|
@@ -41,12 +50,12 @@ yargs(hideBin(process.argv))
|
|
|
41
50
|
}
|
|
42
51
|
)
|
|
43
52
|
.command(
|
|
44
|
-
"db:
|
|
45
|
-
"Running prisma
|
|
53
|
+
"db:seed",
|
|
54
|
+
"Running prisma db seed",
|
|
46
55
|
() => {},
|
|
47
56
|
() => {
|
|
48
|
-
const
|
|
49
|
-
|
|
57
|
+
const dbgenerate = require("./craft/commands/db-seed.js");
|
|
58
|
+
dbgenerate();
|
|
50
59
|
}
|
|
51
60
|
)
|
|
52
61
|
.command(
|
|
@@ -60,7 +69,7 @@ yargs(hideBin(process.argv))
|
|
|
60
69
|
)
|
|
61
70
|
.command(
|
|
62
71
|
"key:generate",
|
|
63
|
-
"Generate
|
|
72
|
+
"Generate App Secret, jwt, and cookie encryption",
|
|
64
73
|
() => {},
|
|
65
74
|
() => {
|
|
66
75
|
const dev = require("./craft/commands/key-generate.js");
|
|
@@ -115,6 +124,20 @@ yargs(hideBin(process.argv))
|
|
|
115
124
|
makecontroller(argv.name, { resource: argv.resource });
|
|
116
125
|
}
|
|
117
126
|
)
|
|
127
|
+
.command(
|
|
128
|
+
"make:dto <name>",
|
|
129
|
+
"Generate a new dto",
|
|
130
|
+
(yargs) => {
|
|
131
|
+
yargs.positional("name", {
|
|
132
|
+
describe: "Dto name",
|
|
133
|
+
type: "string",
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
(argv) => {
|
|
137
|
+
const makedto = require("./craft/commands/make-dto.js");
|
|
138
|
+
makedto(argv.name);
|
|
139
|
+
}
|
|
140
|
+
)
|
|
118
141
|
.command(
|
|
119
142
|
"make:middleware <name>",
|
|
120
143
|
"Generate a new middleware",
|
|
@@ -143,20 +166,7 @@ yargs(hideBin(process.argv))
|
|
|
143
166
|
makerepository(argv.name);
|
|
144
167
|
}
|
|
145
168
|
)
|
|
146
|
-
|
|
147
|
-
"make:dto <name>",
|
|
148
|
-
"Generate a new dto",
|
|
149
|
-
(yargs) => {
|
|
150
|
-
yargs.positional("name", {
|
|
151
|
-
describe: "Dto name",
|
|
152
|
-
type: "string",
|
|
153
|
-
});
|
|
154
|
-
},
|
|
155
|
-
(argv) => {
|
|
156
|
-
const makedto = require("./craft/commands/make-dto.js");
|
|
157
|
-
makedto(argv.name);
|
|
158
|
-
}
|
|
159
|
-
)
|
|
169
|
+
|
|
160
170
|
.command(
|
|
161
171
|
"make:route <name>",
|
|
162
172
|
"Generate a new route",
|
|
@@ -250,15 +260,6 @@ yargs(hideBin(process.argv))
|
|
|
250
260
|
start();
|
|
251
261
|
}
|
|
252
262
|
)
|
|
253
|
-
.command(
|
|
254
|
-
"build:docker",
|
|
255
|
-
"Docker build for production",
|
|
256
|
-
() => {},
|
|
257
|
-
() => {
|
|
258
|
-
const start = require("./craft/commands/docker-build.js");
|
|
259
|
-
start();
|
|
260
|
-
}
|
|
261
|
-
)
|
|
262
263
|
.command(
|
|
263
264
|
"test",
|
|
264
265
|
"Run Jest unit tests",
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "craftjs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "craftjs",
|
|
9
|
-
"version": "
|
|
9
|
+
"version": "2.0.1",
|
|
10
10
|
"license": "UNLICENSED",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@prisma/adapter-mariadb": "^7.2.0",
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
"supertest": "^7.1.0",
|
|
63
63
|
"ts-jest": "^29.3.4",
|
|
64
64
|
"ts-node": "^10.9.2",
|
|
65
|
+
"tsc-alias": "^1.8.16",
|
|
65
66
|
"tsx": "^4.19.4",
|
|
66
67
|
"typescript": "^5.8.3"
|
|
67
68
|
}
|
|
@@ -2880,6 +2881,44 @@
|
|
|
2880
2881
|
"url": "https://paulmillr.com/funding/"
|
|
2881
2882
|
}
|
|
2882
2883
|
},
|
|
2884
|
+
"node_modules/@nodelib/fs.scandir": {
|
|
2885
|
+
"version": "2.1.5",
|
|
2886
|
+
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
|
|
2887
|
+
"integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==",
|
|
2888
|
+
"dev": true,
|
|
2889
|
+
"license": "MIT",
|
|
2890
|
+
"dependencies": {
|
|
2891
|
+
"@nodelib/fs.stat": "2.0.5",
|
|
2892
|
+
"run-parallel": "^1.1.9"
|
|
2893
|
+
},
|
|
2894
|
+
"engines": {
|
|
2895
|
+
"node": ">= 8"
|
|
2896
|
+
}
|
|
2897
|
+
},
|
|
2898
|
+
"node_modules/@nodelib/fs.stat": {
|
|
2899
|
+
"version": "2.0.5",
|
|
2900
|
+
"resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz",
|
|
2901
|
+
"integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==",
|
|
2902
|
+
"dev": true,
|
|
2903
|
+
"license": "MIT",
|
|
2904
|
+
"engines": {
|
|
2905
|
+
"node": ">= 8"
|
|
2906
|
+
}
|
|
2907
|
+
},
|
|
2908
|
+
"node_modules/@nodelib/fs.walk": {
|
|
2909
|
+
"version": "1.2.8",
|
|
2910
|
+
"resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz",
|
|
2911
|
+
"integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==",
|
|
2912
|
+
"dev": true,
|
|
2913
|
+
"license": "MIT",
|
|
2914
|
+
"dependencies": {
|
|
2915
|
+
"@nodelib/fs.scandir": "2.1.5",
|
|
2916
|
+
"fastq": "^1.6.0"
|
|
2917
|
+
},
|
|
2918
|
+
"engines": {
|
|
2919
|
+
"node": ">= 8"
|
|
2920
|
+
}
|
|
2921
|
+
},
|
|
2883
2922
|
"node_modules/@paralleldrive/cuid2": {
|
|
2884
2923
|
"version": "2.2.2",
|
|
2885
2924
|
"resolved": "https://registry.npmjs.org/@paralleldrive/cuid2/-/cuid2-2.2.2.tgz",
|
|
@@ -3696,6 +3735,16 @@
|
|
|
3696
3735
|
"sprintf-js": "~1.0.2"
|
|
3697
3736
|
}
|
|
3698
3737
|
},
|
|
3738
|
+
"node_modules/array-union": {
|
|
3739
|
+
"version": "2.1.0",
|
|
3740
|
+
"resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz",
|
|
3741
|
+
"integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==",
|
|
3742
|
+
"dev": true,
|
|
3743
|
+
"license": "MIT",
|
|
3744
|
+
"engines": {
|
|
3745
|
+
"node": ">=8"
|
|
3746
|
+
}
|
|
3747
|
+
},
|
|
3699
3748
|
"node_modules/asap": {
|
|
3700
3749
|
"version": "2.0.6",
|
|
3701
3750
|
"resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz",
|
|
@@ -4829,6 +4878,19 @@
|
|
|
4829
4878
|
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
|
|
4830
4879
|
}
|
|
4831
4880
|
},
|
|
4881
|
+
"node_modules/dir-glob": {
|
|
4882
|
+
"version": "3.0.1",
|
|
4883
|
+
"resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz",
|
|
4884
|
+
"integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==",
|
|
4885
|
+
"dev": true,
|
|
4886
|
+
"license": "MIT",
|
|
4887
|
+
"dependencies": {
|
|
4888
|
+
"path-type": "^4.0.0"
|
|
4889
|
+
},
|
|
4890
|
+
"engines": {
|
|
4891
|
+
"node": ">=8"
|
|
4892
|
+
}
|
|
4893
|
+
},
|
|
4832
4894
|
"node_modules/doctrine": {
|
|
4833
4895
|
"version": "3.0.0",
|
|
4834
4896
|
"resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz",
|
|
@@ -5287,6 +5349,23 @@
|
|
|
5287
5349
|
"node": ">=8.0.0"
|
|
5288
5350
|
}
|
|
5289
5351
|
},
|
|
5352
|
+
"node_modules/fast-glob": {
|
|
5353
|
+
"version": "3.3.3",
|
|
5354
|
+
"resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.3.tgz",
|
|
5355
|
+
"integrity": "sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==",
|
|
5356
|
+
"dev": true,
|
|
5357
|
+
"license": "MIT",
|
|
5358
|
+
"dependencies": {
|
|
5359
|
+
"@nodelib/fs.stat": "^2.0.2",
|
|
5360
|
+
"@nodelib/fs.walk": "^1.2.3",
|
|
5361
|
+
"glob-parent": "^5.1.2",
|
|
5362
|
+
"merge2": "^1.3.0",
|
|
5363
|
+
"micromatch": "^4.0.8"
|
|
5364
|
+
},
|
|
5365
|
+
"engines": {
|
|
5366
|
+
"node": ">=8.6.0"
|
|
5367
|
+
}
|
|
5368
|
+
},
|
|
5290
5369
|
"node_modules/fast-json-stable-stringify": {
|
|
5291
5370
|
"version": "2.1.0",
|
|
5292
5371
|
"resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz",
|
|
@@ -5301,6 +5380,16 @@
|
|
|
5301
5380
|
"dev": true,
|
|
5302
5381
|
"license": "MIT"
|
|
5303
5382
|
},
|
|
5383
|
+
"node_modules/fastq": {
|
|
5384
|
+
"version": "1.20.1",
|
|
5385
|
+
"resolved": "https://registry.npmjs.org/fastq/-/fastq-1.20.1.tgz",
|
|
5386
|
+
"integrity": "sha512-GGToxJ/w1x32s/D2EKND7kTil4n8OVk/9mycTc4VDza13lOvpUZTGX3mFSCtV9ksdGBVzvsyAVLM6mHFThxXxw==",
|
|
5387
|
+
"dev": true,
|
|
5388
|
+
"license": "ISC",
|
|
5389
|
+
"dependencies": {
|
|
5390
|
+
"reusify": "^1.0.4"
|
|
5391
|
+
}
|
|
5392
|
+
},
|
|
5304
5393
|
"node_modules/fb-watchman": {
|
|
5305
5394
|
"version": "2.0.2",
|
|
5306
5395
|
"resolved": "https://registry.npmjs.org/fb-watchman/-/fb-watchman-2.0.2.tgz",
|
|
@@ -5737,6 +5826,27 @@
|
|
|
5737
5826
|
"node": ">=4"
|
|
5738
5827
|
}
|
|
5739
5828
|
},
|
|
5829
|
+
"node_modules/globby": {
|
|
5830
|
+
"version": "11.1.0",
|
|
5831
|
+
"resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz",
|
|
5832
|
+
"integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==",
|
|
5833
|
+
"dev": true,
|
|
5834
|
+
"license": "MIT",
|
|
5835
|
+
"dependencies": {
|
|
5836
|
+
"array-union": "^2.1.0",
|
|
5837
|
+
"dir-glob": "^3.0.1",
|
|
5838
|
+
"fast-glob": "^3.2.9",
|
|
5839
|
+
"ignore": "^5.2.0",
|
|
5840
|
+
"merge2": "^1.4.1",
|
|
5841
|
+
"slash": "^3.0.0"
|
|
5842
|
+
},
|
|
5843
|
+
"engines": {
|
|
5844
|
+
"node": ">=10"
|
|
5845
|
+
},
|
|
5846
|
+
"funding": {
|
|
5847
|
+
"url": "https://github.com/sponsors/sindresorhus"
|
|
5848
|
+
}
|
|
5849
|
+
},
|
|
5740
5850
|
"node_modules/gopd": {
|
|
5741
5851
|
"version": "1.2.0",
|
|
5742
5852
|
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
|
|
@@ -5894,6 +6004,16 @@
|
|
|
5894
6004
|
],
|
|
5895
6005
|
"license": "BSD-3-Clause"
|
|
5896
6006
|
},
|
|
6007
|
+
"node_modules/ignore": {
|
|
6008
|
+
"version": "5.3.2",
|
|
6009
|
+
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz",
|
|
6010
|
+
"integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==",
|
|
6011
|
+
"dev": true,
|
|
6012
|
+
"license": "MIT",
|
|
6013
|
+
"engines": {
|
|
6014
|
+
"node": ">= 4"
|
|
6015
|
+
}
|
|
6016
|
+
},
|
|
5897
6017
|
"node_modules/ignore-by-default": {
|
|
5898
6018
|
"version": "1.0.1",
|
|
5899
6019
|
"resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz",
|
|
@@ -7308,6 +7428,16 @@
|
|
|
7308
7428
|
"dev": true,
|
|
7309
7429
|
"license": "MIT"
|
|
7310
7430
|
},
|
|
7431
|
+
"node_modules/merge2": {
|
|
7432
|
+
"version": "1.4.1",
|
|
7433
|
+
"resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz",
|
|
7434
|
+
"integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==",
|
|
7435
|
+
"dev": true,
|
|
7436
|
+
"license": "MIT",
|
|
7437
|
+
"engines": {
|
|
7438
|
+
"node": ">= 8"
|
|
7439
|
+
}
|
|
7440
|
+
},
|
|
7311
7441
|
"node_modules/methods": {
|
|
7312
7442
|
"version": "1.1.2",
|
|
7313
7443
|
"resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
|
|
@@ -7408,6 +7538,20 @@
|
|
|
7408
7538
|
"integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==",
|
|
7409
7539
|
"license": "ISC"
|
|
7410
7540
|
},
|
|
7541
|
+
"node_modules/mylas": {
|
|
7542
|
+
"version": "2.1.14",
|
|
7543
|
+
"resolved": "https://registry.npmjs.org/mylas/-/mylas-2.1.14.tgz",
|
|
7544
|
+
"integrity": "sha512-BzQguy9W9NJgoVn2mRWzbFrFWWztGCcng2QI9+41frfk+Athwgx3qhqhvStz7ExeUUu7Kzw427sNzHpEZNINog==",
|
|
7545
|
+
"dev": true,
|
|
7546
|
+
"license": "MIT",
|
|
7547
|
+
"engines": {
|
|
7548
|
+
"node": ">=16.0.0"
|
|
7549
|
+
},
|
|
7550
|
+
"funding": {
|
|
7551
|
+
"type": "github",
|
|
7552
|
+
"url": "https://github.com/sponsors/raouldeheer"
|
|
7553
|
+
}
|
|
7554
|
+
},
|
|
7411
7555
|
"node_modules/mysql2": {
|
|
7412
7556
|
"version": "3.15.3",
|
|
7413
7557
|
"resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.15.3.tgz",
|
|
@@ -7882,6 +8026,16 @@
|
|
|
7882
8026
|
"node": ">=16"
|
|
7883
8027
|
}
|
|
7884
8028
|
},
|
|
8029
|
+
"node_modules/path-type": {
|
|
8030
|
+
"version": "4.0.0",
|
|
8031
|
+
"resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz",
|
|
8032
|
+
"integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==",
|
|
8033
|
+
"dev": true,
|
|
8034
|
+
"license": "MIT",
|
|
8035
|
+
"engines": {
|
|
8036
|
+
"node": ">=8"
|
|
8037
|
+
}
|
|
8038
|
+
},
|
|
7885
8039
|
"node_modules/pathe": {
|
|
7886
8040
|
"version": "2.0.3",
|
|
7887
8041
|
"resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz",
|
|
@@ -7951,6 +8105,19 @@
|
|
|
7951
8105
|
"pathe": "^2.0.3"
|
|
7952
8106
|
}
|
|
7953
8107
|
},
|
|
8108
|
+
"node_modules/plimit-lit": {
|
|
8109
|
+
"version": "1.6.1",
|
|
8110
|
+
"resolved": "https://registry.npmjs.org/plimit-lit/-/plimit-lit-1.6.1.tgz",
|
|
8111
|
+
"integrity": "sha512-B7+VDyb8Tl6oMJT9oSO2CW8XC/T4UcJGrwOVoNGwOQsQYhlpfajmrMj5xeejqaASq3V/EqThyOeATEOMuSEXiA==",
|
|
8112
|
+
"dev": true,
|
|
8113
|
+
"license": "MIT",
|
|
8114
|
+
"dependencies": {
|
|
8115
|
+
"queue-lit": "^1.5.1"
|
|
8116
|
+
},
|
|
8117
|
+
"engines": {
|
|
8118
|
+
"node": ">=12"
|
|
8119
|
+
}
|
|
8120
|
+
},
|
|
7954
8121
|
"node_modules/postgres": {
|
|
7955
8122
|
"version": "3.4.7",
|
|
7956
8123
|
"resolved": "https://registry.npmjs.org/postgres/-/postgres-3.4.7.tgz",
|
|
@@ -8119,6 +8286,37 @@
|
|
|
8119
8286
|
"url": "https://github.com/sponsors/ljharb"
|
|
8120
8287
|
}
|
|
8121
8288
|
},
|
|
8289
|
+
"node_modules/queue-lit": {
|
|
8290
|
+
"version": "1.5.2",
|
|
8291
|
+
"resolved": "https://registry.npmjs.org/queue-lit/-/queue-lit-1.5.2.tgz",
|
|
8292
|
+
"integrity": "sha512-tLc36IOPeMAubu8BkW8YDBV+WyIgKlYU7zUNs0J5Vk9skSZ4JfGlPOqplP0aHdfv7HL0B2Pg6nwiq60Qc6M2Hw==",
|
|
8293
|
+
"dev": true,
|
|
8294
|
+
"license": "MIT",
|
|
8295
|
+
"engines": {
|
|
8296
|
+
"node": ">=12"
|
|
8297
|
+
}
|
|
8298
|
+
},
|
|
8299
|
+
"node_modules/queue-microtask": {
|
|
8300
|
+
"version": "1.2.3",
|
|
8301
|
+
"resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz",
|
|
8302
|
+
"integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==",
|
|
8303
|
+
"dev": true,
|
|
8304
|
+
"funding": [
|
|
8305
|
+
{
|
|
8306
|
+
"type": "github",
|
|
8307
|
+
"url": "https://github.com/sponsors/feross"
|
|
8308
|
+
},
|
|
8309
|
+
{
|
|
8310
|
+
"type": "patreon",
|
|
8311
|
+
"url": "https://www.patreon.com/feross"
|
|
8312
|
+
},
|
|
8313
|
+
{
|
|
8314
|
+
"type": "consulting",
|
|
8315
|
+
"url": "https://feross.org/support"
|
|
8316
|
+
}
|
|
8317
|
+
],
|
|
8318
|
+
"license": "MIT"
|
|
8319
|
+
},
|
|
8122
8320
|
"node_modules/range-parser": {
|
|
8123
8321
|
"version": "1.2.1",
|
|
8124
8322
|
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
|
|
@@ -8410,6 +8608,17 @@
|
|
|
8410
8608
|
"node": ">= 4"
|
|
8411
8609
|
}
|
|
8412
8610
|
},
|
|
8611
|
+
"node_modules/reusify": {
|
|
8612
|
+
"version": "1.1.0",
|
|
8613
|
+
"resolved": "https://registry.npmjs.org/reusify/-/reusify-1.1.0.tgz",
|
|
8614
|
+
"integrity": "sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw==",
|
|
8615
|
+
"dev": true,
|
|
8616
|
+
"license": "MIT",
|
|
8617
|
+
"engines": {
|
|
8618
|
+
"iojs": ">=1.0.0",
|
|
8619
|
+
"node": ">=0.10.0"
|
|
8620
|
+
}
|
|
8621
|
+
},
|
|
8413
8622
|
"node_modules/router": {
|
|
8414
8623
|
"version": "2.2.0",
|
|
8415
8624
|
"resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz",
|
|
@@ -8435,6 +8644,30 @@
|
|
|
8435
8644
|
"node": ">=0.12.0"
|
|
8436
8645
|
}
|
|
8437
8646
|
},
|
|
8647
|
+
"node_modules/run-parallel": {
|
|
8648
|
+
"version": "1.2.0",
|
|
8649
|
+
"resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz",
|
|
8650
|
+
"integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==",
|
|
8651
|
+
"dev": true,
|
|
8652
|
+
"funding": [
|
|
8653
|
+
{
|
|
8654
|
+
"type": "github",
|
|
8655
|
+
"url": "https://github.com/sponsors/feross"
|
|
8656
|
+
},
|
|
8657
|
+
{
|
|
8658
|
+
"type": "patreon",
|
|
8659
|
+
"url": "https://www.patreon.com/feross"
|
|
8660
|
+
},
|
|
8661
|
+
{
|
|
8662
|
+
"type": "consulting",
|
|
8663
|
+
"url": "https://feross.org/support"
|
|
8664
|
+
}
|
|
8665
|
+
],
|
|
8666
|
+
"license": "MIT",
|
|
8667
|
+
"dependencies": {
|
|
8668
|
+
"queue-microtask": "^1.2.2"
|
|
8669
|
+
}
|
|
8670
|
+
},
|
|
8438
8671
|
"node_modules/rxjs": {
|
|
8439
8672
|
"version": "7.8.2",
|
|
8440
8673
|
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.2.tgz",
|
|
@@ -9231,6 +9464,38 @@
|
|
|
9231
9464
|
}
|
|
9232
9465
|
}
|
|
9233
9466
|
},
|
|
9467
|
+
"node_modules/tsc-alias": {
|
|
9468
|
+
"version": "1.8.16",
|
|
9469
|
+
"resolved": "https://registry.npmjs.org/tsc-alias/-/tsc-alias-1.8.16.tgz",
|
|
9470
|
+
"integrity": "sha512-QjCyu55NFyRSBAl6+MTFwplpFcnm2Pq01rR/uxfqJoLMm6X3O14KEGtaSDZpJYaE1bJBGDjD0eSuiIWPe2T58g==",
|
|
9471
|
+
"dev": true,
|
|
9472
|
+
"license": "MIT",
|
|
9473
|
+
"dependencies": {
|
|
9474
|
+
"chokidar": "^3.5.3",
|
|
9475
|
+
"commander": "^9.0.0",
|
|
9476
|
+
"get-tsconfig": "^4.10.0",
|
|
9477
|
+
"globby": "^11.0.4",
|
|
9478
|
+
"mylas": "^2.1.9",
|
|
9479
|
+
"normalize-path": "^3.0.0",
|
|
9480
|
+
"plimit-lit": "^1.2.6"
|
|
9481
|
+
},
|
|
9482
|
+
"bin": {
|
|
9483
|
+
"tsc-alias": "dist/bin/index.js"
|
|
9484
|
+
},
|
|
9485
|
+
"engines": {
|
|
9486
|
+
"node": ">=16.20.2"
|
|
9487
|
+
}
|
|
9488
|
+
},
|
|
9489
|
+
"node_modules/tsc-alias/node_modules/commander": {
|
|
9490
|
+
"version": "9.5.0",
|
|
9491
|
+
"resolved": "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz",
|
|
9492
|
+
"integrity": "sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==",
|
|
9493
|
+
"dev": true,
|
|
9494
|
+
"license": "MIT",
|
|
9495
|
+
"engines": {
|
|
9496
|
+
"node": "^12.20.0 || >=14"
|
|
9497
|
+
}
|
|
9498
|
+
},
|
|
9234
9499
|
"node_modules/tslib": {
|
|
9235
9500
|
"version": "2.8.1",
|
|
9236
9501
|
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
|
package/template/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "craftjs",
|
|
3
3
|
"description": "A starter kit backend framework powered by Express, TypeScript, EJS Engine, and Prisma — designed for rapid development, simplicity, and scalability.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.1",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"express",
|
|
7
7
|
"typescript",
|
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
"supertest": "^7.1.0",
|
|
77
77
|
"ts-jest": "^29.3.4",
|
|
78
78
|
"ts-node": "^10.9.2",
|
|
79
|
+
"tsc-alias": "^1.8.16",
|
|
79
80
|
"tsx": "^4.19.4",
|
|
80
81
|
"typescript": "^5.8.3"
|
|
81
82
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PrismaClient } from "@prisma/client";
|
|
2
2
|
import { PrismaMariaDb } from "@prisma/adapter-mariadb";
|
|
3
|
-
import { logger } from "
|
|
4
|
-
import { dbLogger } from "
|
|
3
|
+
import { logger } from "@config/logger";
|
|
4
|
+
import { dbLogger } from "@config/logger";
|
|
5
5
|
|
|
6
6
|
import { env } from "./env";
|
|
7
7
|
|
|
@@ -16,7 +16,7 @@ const adapter = new PrismaMariaDb({
|
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
export const prismaClient = new PrismaClient({
|
|
19
|
-
|
|
19
|
+
adapter,
|
|
20
20
|
log: [
|
|
21
21
|
{
|
|
22
22
|
emit: "event",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import nodemailer from "nodemailer";
|
|
2
|
-
import { logger } from "
|
|
3
|
-
import { env } from "
|
|
2
|
+
import { logger } from "@config/logger";
|
|
3
|
+
import { env } from "@config/env";
|
|
4
4
|
|
|
5
5
|
const transporter = nodemailer.createTransport({
|
|
6
6
|
host: env.MAIL_HOST,
|
|
@@ -2,15 +2,15 @@ import express from "express";
|
|
|
2
2
|
import fileUpload from "express-fileupload";
|
|
3
3
|
import cors from "cors";
|
|
4
4
|
import cookieParser from "cookie-parser";
|
|
5
|
-
import { env } from "
|
|
5
|
+
import { env } from "@config/env";
|
|
6
6
|
// import expressLayouts from "express-ejs-layouts";
|
|
7
7
|
// import path from "path";
|
|
8
8
|
|
|
9
|
-
import { errorMiddleware } from "
|
|
10
|
-
import { httpLogger } from "
|
|
11
|
-
import { errorResponse } from "
|
|
12
|
-
import { setupSwagger } from "
|
|
13
|
-
import { mainRouter } from "
|
|
9
|
+
import { errorMiddleware } from "@middleware/error-middleware";
|
|
10
|
+
import { httpLogger } from "@middleware/http-logger-middleware";
|
|
11
|
+
import { errorResponse } from "@utils/response";
|
|
12
|
+
import { setupSwagger } from "@utils/swagger";
|
|
13
|
+
import { mainRouter } from "@routes/main-route";
|
|
14
14
|
|
|
15
15
|
export const web = express();
|
|
16
16
|
// EJS View Engine Setup
|
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
loginRequest,
|
|
4
4
|
CreateUserRequest,
|
|
5
5
|
UpdateUserRequest,
|
|
6
|
-
} from "
|
|
7
|
-
import { successResponse } from "
|
|
8
|
-
import { AuthService } from "
|
|
9
|
-
import { UserRequest } from "
|
|
10
|
-
import { env } from "
|
|
6
|
+
} from "@dtos/user-dto";
|
|
7
|
+
import { successResponse } from "@utils/response";
|
|
8
|
+
import { AuthService } from "@services/auth-service";
|
|
9
|
+
import { UserRequest } from "@utils/type-request";
|
|
10
|
+
import { env } from "@config/env";
|
|
11
11
|
|
|
12
12
|
export class AuthController {
|
|
13
13
|
static async register(req: Request, res: Response, next: NextFunction) {
|
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
CreateUserRequest,
|
|
4
4
|
ListUserRequest,
|
|
5
5
|
UpdateUserRequest,
|
|
6
|
-
} from "
|
|
7
|
-
import { UserService } from "
|
|
8
|
-
import { successResponse, paginateResponse } from "
|
|
9
|
-
import { UserRequest } from "
|
|
10
|
-
import { env } from "
|
|
6
|
+
} from "@dtos/user-dto";
|
|
7
|
+
import { UserService } from "@services/user-service";
|
|
8
|
+
import { successResponse, paginateResponse } from "@utils/response";
|
|
9
|
+
import { UserRequest } from "@utils/type-request";
|
|
10
|
+
import { env } from "@config/env";
|
|
11
11
|
export class UserController {
|
|
12
12
|
static async get(req: Request, res: Response, next: NextFunction) {
|
|
13
13
|
try {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { NextFunction, Response } from "express";
|
|
2
2
|
import jwt from "jsonwebtoken";
|
|
3
|
-
import { UserRequest } from "
|
|
4
|
-
import { errorResponse } from "
|
|
5
|
-
import { ResponseError } from "
|
|
6
|
-
import { env } from "
|
|
7
|
-
import { UserRepository } from "
|
|
8
|
-
import { asyncHandler } from "
|
|
3
|
+
import { UserRequest } from "@utils/type-request";
|
|
4
|
+
import { errorResponse } from "@utils/response";
|
|
5
|
+
import { ResponseError } from "@utils/response-error";
|
|
6
|
+
import { env } from "@config/env";
|
|
7
|
+
import { UserRepository } from "@repositories/user-repository";
|
|
8
|
+
import { asyncHandler } from "@utils/async-handler";
|
|
9
9
|
|
|
10
10
|
export const authMiddleware = asyncHandler(
|
|
11
11
|
async (req: UserRequest, res: Response, next: NextFunction) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NextFunction, Request, Response } from "express";
|
|
2
2
|
import { ZodError } from "zod";
|
|
3
|
-
import { errorResponse } from "
|
|
4
|
-
import { ResponseError } from "
|
|
3
|
+
import { errorResponse } from "@utils/response";
|
|
4
|
+
import { ResponseError } from "@utils/response-error";
|
|
5
5
|
|
|
6
6
|
export const errorMiddleware = async (
|
|
7
7
|
error: Error,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import express from "express";
|
|
2
|
-
import { authMiddleware } from "
|
|
2
|
+
import { authMiddleware } from "@middleware/auth-middleware";
|
|
3
|
+
import { AuthController } from "@controllers/auth-controller";
|
|
3
4
|
|
|
4
|
-
import { AuthController } from "../controllers/auth-controller";
|
|
5
5
|
export const authRouter = express.Router();
|
|
6
6
|
authRouter.post("/api/auth/register", AuthController.register);
|
|
7
7
|
authRouter.post("/api/auth/login", AuthController.login);
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import express from "express";
|
|
2
|
-
import { successResponse } from "
|
|
3
|
-
import { authRouter } from "
|
|
4
|
-
import { userRouter } from "
|
|
2
|
+
import { successResponse } from "@utils/response";
|
|
3
|
+
import { authRouter } from "@routes/auth-route";
|
|
4
|
+
import { userRouter } from "@routes/user-route";
|
|
5
5
|
|
|
6
6
|
export const mainRouter = express.Router();
|
|
7
|
-
|
|
8
7
|
// mainRouter.get("/", (req, res) => {
|
|
9
8
|
// res.render("index", { title: "Home Page" });
|
|
10
9
|
// });
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import express from "express";
|
|
2
|
-
import { UserController } from "
|
|
3
|
-
import { authMiddleware } from "
|
|
2
|
+
import { UserController } from "@controllers/user-controller";
|
|
3
|
+
import { authMiddleware } from "@middleware/auth-middleware";
|
|
4
4
|
|
|
5
5
|
export const userRouter = express.Router();
|
|
6
|
-
|
|
7
6
|
userRouter.post("/api/users", authMiddleware, UserController.create);
|
|
8
7
|
userRouter.get("/api/users", authMiddleware, UserController.get);
|
|
9
8
|
userRouter.get("/api/users/:id", authMiddleware, UserController.detail);
|
|
@@ -6,20 +6,20 @@ import {
|
|
|
6
6
|
loginRequest,
|
|
7
7
|
CreateUserRequest,
|
|
8
8
|
UpdateUserRequest,
|
|
9
|
-
} from "
|
|
10
|
-
import { ResponseError } from "
|
|
11
|
-
import { UserValidation } from "
|
|
12
|
-
import { Validation } from "
|
|
9
|
+
} from "@dtos/user-dto";
|
|
10
|
+
import { ResponseError } from "@utils/response-error";
|
|
11
|
+
import { UserValidation } from "@validations/user-validation";
|
|
12
|
+
import { Validation } from "@utils/validation";
|
|
13
13
|
import * as argon2 from "argon2";
|
|
14
14
|
import { User } from "@prisma/client";
|
|
15
15
|
import jwt from "jsonwebtoken";
|
|
16
16
|
import { Request } from "express";
|
|
17
|
-
import { UserRepository } from "
|
|
18
|
-
import { UserRequest } from "
|
|
19
|
-
import { prismaClient } from "
|
|
20
|
-
import { env } from "
|
|
21
|
-
import { decryptCookie, encryptCookie } from "
|
|
22
|
-
import { AuthTokenRepository } from "
|
|
17
|
+
import { UserRepository } from "@repositories/user-repository";
|
|
18
|
+
import { UserRequest } from "@utils/type-request";
|
|
19
|
+
import { prismaClient } from "@config/database";
|
|
20
|
+
import { env } from "@config/env";
|
|
21
|
+
import { decryptCookie, encryptCookie } from "@utils/cookieEncrypt";
|
|
22
|
+
import { AuthTokenRepository } from "@repositories/auth-token-repository";
|
|
23
23
|
|
|
24
24
|
export class AuthService {
|
|
25
25
|
static async register(request: CreateUserRequest): Promise<UserResponse> {
|
|
@@ -6,14 +6,14 @@ import {
|
|
|
6
6
|
UserResponse,
|
|
7
7
|
toUserListItemResponse,
|
|
8
8
|
UserListItemResponse,
|
|
9
|
-
} from "
|
|
10
|
-
import { ResponseError } from "
|
|
11
|
-
import { UserValidation } from "
|
|
12
|
-
import { Validation } from "
|
|
9
|
+
} from "@dtos/user-dto";
|
|
10
|
+
import { ResponseError } from "@utils/response-error";
|
|
11
|
+
import { UserValidation } from "@validations/user-validation";
|
|
12
|
+
import { Validation } from "@utils/validation";
|
|
13
13
|
import * as argon2 from "argon2";
|
|
14
|
-
import { UserRepository } from "
|
|
15
|
-
import { buildPaginationLinks } from "
|
|
16
|
-
import { PaginatedResponse } from "
|
|
14
|
+
import { UserRepository } from "@repositories/user-repository";
|
|
15
|
+
import { buildPaginationLinks } from "@utils/pagination";
|
|
16
|
+
import { PaginatedResponse } from "@dtos/pagination-dto";
|
|
17
17
|
export class UserService {
|
|
18
18
|
static async create(request: CreateUserRequest): Promise<UserResponse> {
|
|
19
19
|
const data = Validation.validate(UserValidation.CREATE, request);
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import crypto from "crypto";
|
|
2
|
-
import { env } from "
|
|
2
|
+
import { env } from "@config/env";
|
|
3
3
|
|
|
4
4
|
const ALGORITHM = "aes-256-gcm";
|
|
5
5
|
const IV_LENGTH = 12;
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
const KEY = Buffer.from(env.COOKIE_ENCRYPTION_KEY, "hex");
|
|
9
8
|
|
|
10
9
|
export function encryptCookie(text: string): string {
|
|
@@ -2,7 +2,7 @@ import swaggerJSDoc from "swagger-jsdoc";
|
|
|
2
2
|
import swaggerUi from "swagger-ui-express";
|
|
3
3
|
import { Express } from "express";
|
|
4
4
|
import { SwaggerTheme } from "swagger-themes";
|
|
5
|
-
import { env } from "
|
|
5
|
+
import { env } from "@config/env";
|
|
6
6
|
|
|
7
7
|
function formatAppNameForTitle(appName: string) {
|
|
8
8
|
return appName
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import supertest from "supertest";
|
|
2
|
-
import { web } from "../src/
|
|
3
|
-
import { logger } from "../src/
|
|
2
|
+
import { web } from "../src/config/web";
|
|
3
|
+
import { logger } from "../src/config/logger";
|
|
4
4
|
describe("POST /api/users", () => {
|
|
5
5
|
it("should register new user", async () => {
|
|
6
6
|
const response = await supertest(web).post("/api/auth/register").send({
|
package/template/tsconfig.json
CHANGED
|
@@ -2,10 +2,27 @@
|
|
|
2
2
|
"include": ["src/**/*"],
|
|
3
3
|
"compilerOptions": {
|
|
4
4
|
"rootDir": "src",
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
"paths": {
|
|
7
|
+
"@config/*": ["./src/config/*"],
|
|
8
|
+
"@controllers/*": ["./src/controllers/*"],
|
|
9
|
+
"@services/*": ["./src/services/*"],
|
|
10
|
+
"@repositories/*": ["./src/repositories/*"],
|
|
11
|
+
"@routes/*": ["./src/routes/*"],
|
|
12
|
+
"@middleware/*": ["./src/middleware/*"],
|
|
13
|
+
"@dtos/*": ["./src/dtos/*"],
|
|
14
|
+
"@types/*": ["./src/types/*"],
|
|
15
|
+
"@utils/*": ["./src/utils/*"],
|
|
16
|
+
"@validations/*": ["./src/validations/*"],
|
|
17
|
+
"@views/*": ["./src/views/*"],
|
|
18
|
+
"@apidocs/*": ["./src/apidocs/*"],
|
|
19
|
+
"@db": ["./prisma/*"]
|
|
20
|
+
},
|
|
21
|
+
|
|
6
22
|
"target": "ES2020",
|
|
7
23
|
"module": "Node16",
|
|
8
24
|
"moduleResolution": "Node16",
|
|
25
|
+
"outDir": "./build",
|
|
9
26
|
"esModuleInterop": true,
|
|
10
27
|
"forceConsistentCasingInFileNames": true,
|
|
11
28
|
"strict": true,
|
|
File without changes
|
|
File without changes
|