create-craftjs 1.0.4 → 1.0.6
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 +139 -137
- package/bin/index.js +158 -158
- package/package.json +24 -24
- package/template/Dockerfile +57 -12
- package/template/babel.config.json +3 -3
- package/template/craft/commands/build.js +16 -15
- package/template/craft/commands/db-fresh.js +22 -22
- package/template/craft/commands/db-generate.js +23 -23
- package/template/craft/commands/db-migrate.js +22 -22
- package/template/craft/commands/dev.js +16 -16
- package/template/craft/commands/key-generate.js +41 -41
- package/template/craft/commands/make-apidocs.js +121 -121
- package/template/craft/commands/make-command.js +38 -38
- package/template/craft/commands/make-controller.js +95 -95
- package/template/craft/commands/make-dto.js +39 -39
- package/template/craft/commands/make-middleware.js +46 -46
- package/template/craft/commands/make-repository.js +36 -36
- package/template/craft/commands/make-route.js +92 -92
- package/template/craft/commands/make-service.js +39 -39
- package/template/craft/commands/make-test.js +48 -48
- package/template/craft/commands/make-utils.js +30 -30
- package/template/craft/commands/make-validation.js +42 -42
- package/template/craft/commands/make-view.js +42 -42
- package/template/craft/commands/start.js +29 -29
- package/template/craft/commands/test.js +20 -20
- package/template/craft.js +256 -256
- package/template/docker-compose.yml +8 -0
- package/template/nodemon.json +6 -6
- package/template/package-lock.json +8877 -8877
- package/template/package.json +84 -84
- package/template/prisma/schema.prisma +22 -22
- package/template/prisma/seed.ts +29 -29
- package/template/src/apidocs/auth-docs.ts +314 -314
- package/template/src/apidocs/users-docs.ts +240 -240
- package/template/src/config/cloudinary.ts +21 -21
- package/template/src/config/database.ts +90 -90
- package/template/src/config/env.ts +67 -67
- package/template/src/config/logger.ts +139 -139
- package/template/src/config/nodemailer.ts +23 -23
- package/template/src/config/web.ts +47 -47
- package/template/src/controllers/auth-controller.ts +88 -88
- package/template/src/controllers/user-controller.ts +79 -79
- package/template/src/dtos/list-dto.ts +12 -12
- package/template/src/dtos/user-dto.ts +57 -57
- package/template/src/main.ts +28 -28
- package/template/src/middleware/auth-middleware.ts +44 -44
- package/template/src/middleware/error-middleware.ts +27 -27
- package/template/src/middleware/http-logger-middleware.ts +31 -31
- package/template/src/repositories/user-repository.ts +75 -75
- package/template/src/routes/auth-route.ts +20 -20
- package/template/src/routes/main-route.ts +25 -25
- package/template/src/routes/user-route.ts +35 -35
- package/template/src/services/auth-service.ts +162 -162
- package/template/src/services/user-service.ts +102 -102
- package/template/src/types/type-request.ts +6 -6
- package/template/src/utils/async-handler.ts +9 -9
- package/template/src/utils/response-error.ts +10 -10
- package/template/src/utils/response.ts +60 -60
- package/template/src/utils/swagger.ts +135 -135
- package/template/src/utils/validation.ts +7 -7
- package/template/src/validations/user-validation.ts +127 -127
- package/template/src/views/index.ejs +6 -6
- package/template/src/views/layouts/main.ejs +14 -14
- package/template/src/views/partials/header.ejs +3 -3
- package/template/test/user.test.ts +16 -16
- package/template/tsconfig.json +13 -13
- package/template/.dockerignore +0 -4
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import { NextFunction, Response } from "express";
|
|
2
|
-
import { errorResponse } from "../utils/response";
|
|
3
|
-
import { prismaClient } from "../config/database";
|
|
4
|
-
import jwt from "jsonwebtoken";
|
|
5
|
-
import { UserRequest } from "../types/type-request";
|
|
6
|
-
import { ResponseError } from "../utils/response-error";
|
|
7
|
-
import { env } from "../config/env";
|
|
8
|
-
|
|
9
|
-
export const authMiddleware = async (
|
|
10
|
-
req: UserRequest,
|
|
11
|
-
res: Response,
|
|
12
|
-
next: NextFunction
|
|
13
|
-
) => {
|
|
14
|
-
const refreshToken = req.cookies.refresh_token;
|
|
15
|
-
if (!refreshToken) {
|
|
16
|
-
throw new ResponseError(401, "Unauthorized: Anda Belum Login.");
|
|
17
|
-
}
|
|
18
|
-
const token = req.get("Authorization")?.split(" ")[1];
|
|
19
|
-
if (!token) {
|
|
20
|
-
return res
|
|
21
|
-
.status(401)
|
|
22
|
-
.json(errorResponse("Unauthorized: Access Token Tidak Valid.", 401));
|
|
23
|
-
}
|
|
24
|
-
let payload;
|
|
25
|
-
try {
|
|
26
|
-
payload = jwt.verify(token, env.JWT_SECRET as string) as {
|
|
27
|
-
user_id: string;
|
|
28
|
-
user_email: string;
|
|
29
|
-
user_fullName: string;
|
|
30
|
-
};
|
|
31
|
-
} catch (err) {
|
|
32
|
-
throw new ResponseError(401, "Unauthorized: Access Token Tidak Valid.");
|
|
33
|
-
}
|
|
34
|
-
const user = await prismaClient.user.findUnique({
|
|
35
|
-
where: { id: payload.user_id },
|
|
36
|
-
});
|
|
37
|
-
if (!user) {
|
|
38
|
-
return res
|
|
39
|
-
.status(401)
|
|
40
|
-
.json(errorResponse("Unauthorized: Anda belum login", 401));
|
|
41
|
-
}
|
|
42
|
-
req.user = user;
|
|
43
|
-
next();
|
|
44
|
-
};
|
|
1
|
+
import { NextFunction, Response } from "express";
|
|
2
|
+
import { errorResponse } from "../utils/response";
|
|
3
|
+
import { prismaClient } from "../config/database";
|
|
4
|
+
import jwt from "jsonwebtoken";
|
|
5
|
+
import { UserRequest } from "../types/type-request";
|
|
6
|
+
import { ResponseError } from "../utils/response-error";
|
|
7
|
+
import { env } from "../config/env";
|
|
8
|
+
|
|
9
|
+
export const authMiddleware = async (
|
|
10
|
+
req: UserRequest,
|
|
11
|
+
res: Response,
|
|
12
|
+
next: NextFunction
|
|
13
|
+
) => {
|
|
14
|
+
const refreshToken = req.cookies.refresh_token;
|
|
15
|
+
if (!refreshToken) {
|
|
16
|
+
throw new ResponseError(401, "Unauthorized: Anda Belum Login.");
|
|
17
|
+
}
|
|
18
|
+
const token = req.get("Authorization")?.split(" ")[1];
|
|
19
|
+
if (!token) {
|
|
20
|
+
return res
|
|
21
|
+
.status(401)
|
|
22
|
+
.json(errorResponse("Unauthorized: Access Token Tidak Valid.", 401));
|
|
23
|
+
}
|
|
24
|
+
let payload;
|
|
25
|
+
try {
|
|
26
|
+
payload = jwt.verify(token, env.JWT_SECRET as string) as {
|
|
27
|
+
user_id: string;
|
|
28
|
+
user_email: string;
|
|
29
|
+
user_fullName: string;
|
|
30
|
+
};
|
|
31
|
+
} catch (err) {
|
|
32
|
+
throw new ResponseError(401, "Unauthorized: Access Token Tidak Valid.");
|
|
33
|
+
}
|
|
34
|
+
const user = await prismaClient.user.findUnique({
|
|
35
|
+
where: { id: payload.user_id },
|
|
36
|
+
});
|
|
37
|
+
if (!user) {
|
|
38
|
+
return res
|
|
39
|
+
.status(401)
|
|
40
|
+
.json(errorResponse("Unauthorized: Anda belum login", 401));
|
|
41
|
+
}
|
|
42
|
+
req.user = user;
|
|
43
|
+
next();
|
|
44
|
+
};
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { NextFunction, Request, Response } from "express";
|
|
2
|
-
import { ZodError } from "zod";
|
|
3
|
-
import { errorResponse } from "../utils/response";
|
|
4
|
-
import { ResponseError } from "../utils/response-error";
|
|
5
|
-
|
|
6
|
-
export const errorMiddleware = async (
|
|
7
|
-
error: Error,
|
|
8
|
-
req: Request,
|
|
9
|
-
res: Response,
|
|
10
|
-
next: NextFunction
|
|
11
|
-
) => {
|
|
12
|
-
if (error instanceof ZodError) {
|
|
13
|
-
let formattedErrors = error.errors.map((err) => ({
|
|
14
|
-
field: err.path.join("."),
|
|
15
|
-
message: err.message,
|
|
16
|
-
}));
|
|
17
|
-
res
|
|
18
|
-
.status(400)
|
|
19
|
-
.json(errorResponse("Validation Error", 400, formattedErrors));
|
|
20
|
-
} else if (error instanceof ResponseError) {
|
|
21
|
-
res
|
|
22
|
-
.status(error.status_code)
|
|
23
|
-
.json(errorResponse(error.message, error.status_code));
|
|
24
|
-
} else {
|
|
25
|
-
res.status(500).json(errorResponse(error.message, 500));
|
|
26
|
-
}
|
|
27
|
-
};
|
|
1
|
+
import { NextFunction, Request, Response } from "express";
|
|
2
|
+
import { ZodError } from "zod";
|
|
3
|
+
import { errorResponse } from "../utils/response";
|
|
4
|
+
import { ResponseError } from "../utils/response-error";
|
|
5
|
+
|
|
6
|
+
export const errorMiddleware = async (
|
|
7
|
+
error: Error,
|
|
8
|
+
req: Request,
|
|
9
|
+
res: Response,
|
|
10
|
+
next: NextFunction
|
|
11
|
+
) => {
|
|
12
|
+
if (error instanceof ZodError) {
|
|
13
|
+
let formattedErrors = error.errors.map((err) => ({
|
|
14
|
+
field: err.path.join("."),
|
|
15
|
+
message: err.message,
|
|
16
|
+
}));
|
|
17
|
+
res
|
|
18
|
+
.status(400)
|
|
19
|
+
.json(errorResponse("Validation Error", 400, formattedErrors));
|
|
20
|
+
} else if (error instanceof ResponseError) {
|
|
21
|
+
res
|
|
22
|
+
.status(error.status_code)
|
|
23
|
+
.json(errorResponse(error.message, error.status_code));
|
|
24
|
+
} else {
|
|
25
|
+
res.status(500).json(errorResponse(error.message, 500));
|
|
26
|
+
}
|
|
27
|
+
};
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { Request, Response, NextFunction } from "express";
|
|
2
|
-
import { httpAccessLogger } from "../config/logger";
|
|
3
|
-
|
|
4
|
-
export const httpLogger = async (
|
|
5
|
-
req: Request,
|
|
6
|
-
res: Response,
|
|
7
|
-
next: NextFunction
|
|
8
|
-
) => {
|
|
9
|
-
const start = process.hrtime();
|
|
10
|
-
|
|
11
|
-
res.on("finish", () => {
|
|
12
|
-
const diff = process.hrtime(start);
|
|
13
|
-
const timeInMs = (diff[0] * 1e3 + diff[1] / 1e6).toFixed(3);
|
|
14
|
-
|
|
15
|
-
const logMessage = `${req.method} ${req.originalUrl} ${res.statusCode} ${timeInMs} ms - ${res.get("Content-Length") || 0}`;
|
|
16
|
-
|
|
17
|
-
if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
18
|
-
httpAccessLogger.info(logMessage);
|
|
19
|
-
} else if (res.statusCode >= 300 && res.statusCode < 400) {
|
|
20
|
-
httpAccessLogger.info(logMessage);
|
|
21
|
-
} else if (res.statusCode >= 400 && res.statusCode < 500) {
|
|
22
|
-
httpAccessLogger.warn(logMessage);
|
|
23
|
-
} else if (res.statusCode >= 500) {
|
|
24
|
-
httpAccessLogger.error(logMessage);
|
|
25
|
-
} else {
|
|
26
|
-
httpAccessLogger.debug(logMessage);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
next();
|
|
31
|
-
};
|
|
1
|
+
import { Request, Response, NextFunction } from "express";
|
|
2
|
+
import { httpAccessLogger } from "../config/logger";
|
|
3
|
+
|
|
4
|
+
export const httpLogger = async (
|
|
5
|
+
req: Request,
|
|
6
|
+
res: Response,
|
|
7
|
+
next: NextFunction
|
|
8
|
+
) => {
|
|
9
|
+
const start = process.hrtime();
|
|
10
|
+
|
|
11
|
+
res.on("finish", () => {
|
|
12
|
+
const diff = process.hrtime(start);
|
|
13
|
+
const timeInMs = (diff[0] * 1e3 + diff[1] / 1e6).toFixed(3);
|
|
14
|
+
|
|
15
|
+
const logMessage = `${req.method} ${req.originalUrl} ${res.statusCode} ${timeInMs} ms - ${res.get("Content-Length") || 0}`;
|
|
16
|
+
|
|
17
|
+
if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
18
|
+
httpAccessLogger.info(logMessage);
|
|
19
|
+
} else if (res.statusCode >= 300 && res.statusCode < 400) {
|
|
20
|
+
httpAccessLogger.info(logMessage);
|
|
21
|
+
} else if (res.statusCode >= 400 && res.statusCode < 500) {
|
|
22
|
+
httpAccessLogger.warn(logMessage);
|
|
23
|
+
} else if (res.statusCode >= 500) {
|
|
24
|
+
httpAccessLogger.error(logMessage);
|
|
25
|
+
} else {
|
|
26
|
+
httpAccessLogger.debug(logMessage);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
next();
|
|
31
|
+
};
|
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
import { prismaClient } from "../config/database";
|
|
2
|
-
|
|
3
|
-
export class UserRepository {
|
|
4
|
-
static async countByEmail(email: string): Promise<number> {
|
|
5
|
-
return prismaClient.user.count({ where: { email } });
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
static async create(data: any) {
|
|
9
|
-
return prismaClient.user.create({ data });
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
static async findMany(filters: any, skip: number, take: number) {
|
|
13
|
-
return prismaClient.user.findMany({
|
|
14
|
-
where: {
|
|
15
|
-
AND: filters,
|
|
16
|
-
deleted_at: null,
|
|
17
|
-
},
|
|
18
|
-
skip,
|
|
19
|
-
take,
|
|
20
|
-
orderBy: { updated_at: "desc" },
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
static async count(filters: any) {
|
|
25
|
-
return prismaClient.user.count({
|
|
26
|
-
where: {
|
|
27
|
-
AND: filters,
|
|
28
|
-
deleted_at: null,
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
static async findById(id: string) {
|
|
34
|
-
return prismaClient.user.findUnique({
|
|
35
|
-
where: { id },
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
static async update(id: string, data: any) {
|
|
40
|
-
return prismaClient.user.update({
|
|
41
|
-
where: { id },
|
|
42
|
-
data,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
static async delete(id: string) {
|
|
47
|
-
return prismaClient.user.delete({ where: { id } });
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
static async findUserByEmail(login: string) {
|
|
51
|
-
return prismaClient.user.findFirst({
|
|
52
|
-
where: {
|
|
53
|
-
email: login,
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
static async updateUser(data: any, id: string) {
|
|
59
|
-
return prismaClient.user.update({
|
|
60
|
-
where: { id },
|
|
61
|
-
data,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
static async findemailExistsNotUserLoggedIn(email: string, idUser: string) {
|
|
66
|
-
return prismaClient.user.count({
|
|
67
|
-
where: {
|
|
68
|
-
email: email,
|
|
69
|
-
NOT: {
|
|
70
|
-
id: idUser,
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
}
|
|
1
|
+
import { prismaClient } from "../config/database";
|
|
2
|
+
|
|
3
|
+
export class UserRepository {
|
|
4
|
+
static async countByEmail(email: string): Promise<number> {
|
|
5
|
+
return prismaClient.user.count({ where: { email } });
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
static async create(data: any) {
|
|
9
|
+
return prismaClient.user.create({ data });
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static async findMany(filters: any, skip: number, take: number) {
|
|
13
|
+
return prismaClient.user.findMany({
|
|
14
|
+
where: {
|
|
15
|
+
AND: filters,
|
|
16
|
+
deleted_at: null,
|
|
17
|
+
},
|
|
18
|
+
skip,
|
|
19
|
+
take,
|
|
20
|
+
orderBy: { updated_at: "desc" },
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static async count(filters: any) {
|
|
25
|
+
return prismaClient.user.count({
|
|
26
|
+
where: {
|
|
27
|
+
AND: filters,
|
|
28
|
+
deleted_at: null,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static async findById(id: string) {
|
|
34
|
+
return prismaClient.user.findUnique({
|
|
35
|
+
where: { id },
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static async update(id: string, data: any) {
|
|
40
|
+
return prismaClient.user.update({
|
|
41
|
+
where: { id },
|
|
42
|
+
data,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static async delete(id: string) {
|
|
47
|
+
return prismaClient.user.delete({ where: { id } });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static async findUserByEmail(login: string) {
|
|
51
|
+
return prismaClient.user.findFirst({
|
|
52
|
+
where: {
|
|
53
|
+
email: login,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static async updateUser(data: any, id: string) {
|
|
59
|
+
return prismaClient.user.update({
|
|
60
|
+
where: { id },
|
|
61
|
+
data,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static async findemailExistsNotUserLoggedIn(email: string, idUser: string) {
|
|
66
|
+
return prismaClient.user.count({
|
|
67
|
+
where: {
|
|
68
|
+
email: email,
|
|
69
|
+
NOT: {
|
|
70
|
+
id: idUser,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import express from "express";
|
|
2
|
-
import { asyncHandler } from "../utils/async-handler";
|
|
3
|
-
import { authMiddleware } from "../middleware/auth-middleware";
|
|
4
|
-
|
|
5
|
-
import { AuthController } from "../controllers/auth-controller";
|
|
6
|
-
export const authRouter = express.Router();
|
|
7
|
-
authRouter.post("/api/auth/register", AuthController.register);
|
|
8
|
-
authRouter.post("/api/auth/login", AuthController.login);
|
|
9
|
-
authRouter.get("/api/auth/me", asyncHandler(authMiddleware), AuthController.me);
|
|
10
|
-
authRouter.post(
|
|
11
|
-
"/api/auth/logout",
|
|
12
|
-
asyncHandler(authMiddleware),
|
|
13
|
-
AuthController.logout
|
|
14
|
-
);
|
|
15
|
-
authRouter.get("/api/auth/refresh-token", AuthController.refreshToken);
|
|
16
|
-
authRouter.put(
|
|
17
|
-
"/api/auth/update-profile",
|
|
18
|
-
asyncHandler(authMiddleware),
|
|
19
|
-
AuthController.updateProfile
|
|
20
|
-
);
|
|
1
|
+
import express from "express";
|
|
2
|
+
import { asyncHandler } from "../utils/async-handler";
|
|
3
|
+
import { authMiddleware } from "../middleware/auth-middleware";
|
|
4
|
+
|
|
5
|
+
import { AuthController } from "../controllers/auth-controller";
|
|
6
|
+
export const authRouter = express.Router();
|
|
7
|
+
authRouter.post("/api/auth/register", AuthController.register);
|
|
8
|
+
authRouter.post("/api/auth/login", AuthController.login);
|
|
9
|
+
authRouter.get("/api/auth/me", asyncHandler(authMiddleware), AuthController.me);
|
|
10
|
+
authRouter.post(
|
|
11
|
+
"/api/auth/logout",
|
|
12
|
+
asyncHandler(authMiddleware),
|
|
13
|
+
AuthController.logout
|
|
14
|
+
);
|
|
15
|
+
authRouter.get("/api/auth/refresh-token", AuthController.refreshToken);
|
|
16
|
+
authRouter.put(
|
|
17
|
+
"/api/auth/update-profile",
|
|
18
|
+
asyncHandler(authMiddleware),
|
|
19
|
+
AuthController.updateProfile
|
|
20
|
+
);
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import express from "express";
|
|
2
|
-
import { successResponse } from "../utils/response";
|
|
3
|
-
import { authRouter } from "./auth-route";
|
|
4
|
-
import { userRouter } from "./user-route";
|
|
5
|
-
|
|
6
|
-
export const mainRouter = express.Router();
|
|
7
|
-
|
|
8
|
-
// mainRouter.get("/", (req, res) => {
|
|
9
|
-
// res.render("index", { title: "Home Page" });
|
|
10
|
-
// });
|
|
11
|
-
|
|
12
|
-
mainRouter.get("/", (req, res) => {
|
|
13
|
-
res
|
|
14
|
-
.status(200)
|
|
15
|
-
.json(successResponse(`${process.env.APP_NAME} is running`, 200))
|
|
16
|
-
.end();
|
|
17
|
-
});
|
|
18
|
-
mainRouter.get("/api", (req, res) => {
|
|
19
|
-
res
|
|
20
|
-
.status(200)
|
|
21
|
-
.json(successResponse(`${process.env.APP_NAME} api is running`, 200))
|
|
22
|
-
.end();
|
|
23
|
-
});
|
|
24
|
-
mainRouter.use(authRouter);
|
|
25
|
-
mainRouter.use(userRouter);
|
|
1
|
+
import express from "express";
|
|
2
|
+
import { successResponse } from "../utils/response";
|
|
3
|
+
import { authRouter } from "./auth-route";
|
|
4
|
+
import { userRouter } from "./user-route";
|
|
5
|
+
|
|
6
|
+
export const mainRouter = express.Router();
|
|
7
|
+
|
|
8
|
+
// mainRouter.get("/", (req, res) => {
|
|
9
|
+
// res.render("index", { title: "Home Page" });
|
|
10
|
+
// });
|
|
11
|
+
|
|
12
|
+
mainRouter.get("/", (req, res) => {
|
|
13
|
+
res
|
|
14
|
+
.status(200)
|
|
15
|
+
.json(successResponse(`${process.env.APP_NAME} is running`, 200))
|
|
16
|
+
.end();
|
|
17
|
+
});
|
|
18
|
+
mainRouter.get("/api", (req, res) => {
|
|
19
|
+
res
|
|
20
|
+
.status(200)
|
|
21
|
+
.json(successResponse(`${process.env.APP_NAME} api is running`, 200))
|
|
22
|
+
.end();
|
|
23
|
+
});
|
|
24
|
+
mainRouter.use(authRouter);
|
|
25
|
+
mainRouter.use(userRouter);
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import express from "express";
|
|
2
|
-
import { UserController } from "../controllers/user-controller";
|
|
3
|
-
import { asyncHandler } from "../utils/async-handler";
|
|
4
|
-
import { authMiddleware } from "../middleware/auth-middleware";
|
|
5
|
-
|
|
6
|
-
export const userRouter = express.Router();
|
|
7
|
-
|
|
8
|
-
userRouter.post(
|
|
9
|
-
"/api/users",
|
|
10
|
-
asyncHandler(authMiddleware),
|
|
11
|
-
UserController.create
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
userRouter.get(
|
|
15
|
-
"/api/users",
|
|
16
|
-
asyncHandler(authMiddleware),
|
|
17
|
-
UserController.getAll
|
|
18
|
-
);
|
|
19
|
-
userRouter.get(
|
|
20
|
-
"/api/users/:id",
|
|
21
|
-
asyncHandler(authMiddleware),
|
|
22
|
-
UserController.getOne
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
userRouter.put(
|
|
26
|
-
"/api/users/:id",
|
|
27
|
-
asyncHandler(authMiddleware),
|
|
28
|
-
UserController.update
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
userRouter.delete(
|
|
32
|
-
"/api/users/:id",
|
|
33
|
-
asyncHandler(authMiddleware),
|
|
34
|
-
UserController.delete
|
|
35
|
-
);
|
|
1
|
+
import express from "express";
|
|
2
|
+
import { UserController } from "../controllers/user-controller";
|
|
3
|
+
import { asyncHandler } from "../utils/async-handler";
|
|
4
|
+
import { authMiddleware } from "../middleware/auth-middleware";
|
|
5
|
+
|
|
6
|
+
export const userRouter = express.Router();
|
|
7
|
+
|
|
8
|
+
userRouter.post(
|
|
9
|
+
"/api/users",
|
|
10
|
+
asyncHandler(authMiddleware),
|
|
11
|
+
UserController.create
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
userRouter.get(
|
|
15
|
+
"/api/users",
|
|
16
|
+
asyncHandler(authMiddleware),
|
|
17
|
+
UserController.getAll
|
|
18
|
+
);
|
|
19
|
+
userRouter.get(
|
|
20
|
+
"/api/users/:id",
|
|
21
|
+
asyncHandler(authMiddleware),
|
|
22
|
+
UserController.getOne
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
userRouter.put(
|
|
26
|
+
"/api/users/:id",
|
|
27
|
+
asyncHandler(authMiddleware),
|
|
28
|
+
UserController.update
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
userRouter.delete(
|
|
32
|
+
"/api/users/:id",
|
|
33
|
+
asyncHandler(authMiddleware),
|
|
34
|
+
UserController.delete
|
|
35
|
+
);
|