diff --git a/src/app.ts b/src/app.ts index 906bbf4..389c402 100644 --- a/src/app.ts +++ b/src/app.ts @@ -30,7 +30,7 @@ export default class ServerApplication { } async serverConfiguration() { - // this.#APP.use(secureApp); + this.#APP.use(secureApp); this.#APP.use(express.json()); this.#APP.use(express.urlencoded({ extended: true })); this.#APP.set("json spaces", 2); diff --git a/src/core/router/main.router.ts b/src/core/router/main.router.ts index 00a0b6d..dd54ec7 100644 --- a/src/core/router/main.router.ts +++ b/src/core/router/main.router.ts @@ -2,6 +2,7 @@ import { Router } from 'express'; import AuthRouter from '../../modules/auth/router/auth.routes'; import formRouter from '../../modules/forms/index.routes'; import userRouter from '../../modules/user/routes/user.routes'; +import CenterRouter from '../../modules/forms/center/routes/center.routes'; const mainRouter = Router(); @@ -9,4 +10,5 @@ const mainRouter = Router(); mainRouter.use('/auth',AuthRouter) mainRouter.use('/user',userRouter) mainRouter.use('/form',formRouter) +mainRouter.use('/center',CenterRouter) export default mainRouter; \ No newline at end of file diff --git a/src/models/Identity.ts b/src/models/Identity.ts index 61d59b5..f1009e0 100644 --- a/src/models/Identity.ts +++ b/src/models/Identity.ts @@ -22,8 +22,10 @@ export interface IdentityAttributes { updatedAt?: Date; } -export interface IdentityCreationAttributes - extends Optional {} +export interface IdentityCreationAttributes extends Optional< + IdentityAttributes, + "id" | "profilePhotoId" +> {} export class Identity extends Model @@ -55,63 +57,64 @@ export class Identity id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, - primaryKey: true + primaryKey: true, }, applicantId: { type: DataTypes.UUID, - allowNull: false + allowNull: false, }, firstName: { type: DataTypes.STRING, - allowNull: false + allowNull: false, }, lastName: { type: DataTypes.STRING, - allowNull: false + allowNull: false, }, fatherName: { - type: DataTypes.STRING + type: DataTypes.STRING, }, nationalCode: { type: DataTypes.STRING(10), - allowNull: false + allowNull: false, }, birthDate: { - type: DataTypes.DATEONLY + type: DataTypes.DATEONLY, }, birthPlace: { - type: DataTypes.STRING + type: DataTypes.STRING, }, gender: { - type: DataTypes.STRING + type: DataTypes.ENUM("male", "female", "other"), + allowNull: true, }, religion: { - type: DataTypes.STRING + type: DataTypes.STRING, }, nationality: { - type: DataTypes.STRING + type: DataTypes.STRING, }, profilePhotoId: { type: DataTypes.UUID, - allowNull: true - } + allowNull: true, + }, }, { sequelize, tableName: "identities", - timestamps: true - } + timestamps: true, + }, ); return Identity; diff --git a/src/modules/auth/controller/auth.controller.ts b/src/modules/auth/controller/auth.controller.ts index 2ded26d..8971653 100644 --- a/src/modules/auth/controller/auth.controller.ts +++ b/src/modules/auth/controller/auth.controller.ts @@ -48,7 +48,7 @@ class AuthControllerClass extends Controller { return res.status(200).json({ status: 200, data, - message: "با موفقيت وارد شديد", + message: "Ok", }); } catch (error) { next(error); diff --git a/src/modules/auth/service/auth.service.ts b/src/modules/auth/service/auth.service.ts index 7093fd7..31bccba 100644 --- a/src/modules/auth/service/auth.service.ts +++ b/src/modules/auth/service/auth.service.ts @@ -57,24 +57,24 @@ class AuthServiceClass extends Controller { ], }); - if (!identity?.applicantId) { - throw new createHttpError.NotFound( - authErrorMessages.notFound.applicant, - ); - } + const token = jwt.sign( - { userId: identity.applicantId }, + { userId: identity?.applicantId }, process.env.JWT_SECRET || "secret", { expiresIn: "24h" }, // طول عمر توکن ); return { token, - applicant: { id: identity.applicantId, fullname: `${identity.firstName} ${identity.lastName}`, role: identity }, + applicant: { + id: identity?.applicantId, + fullname: `${identity?.firstName} ${identity?.lastName}`, + role: identity, + }, }; } catch (error) { - throw new createHttpError.InternalServerError("خطای سرور"); + throw error; } } } diff --git a/src/modules/forms/center/routes/center.routes.ts b/src/modules/forms/center/routes/center.routes.ts index 688cfbd..b46ac0c 100644 --- a/src/modules/forms/center/routes/center.routes.ts +++ b/src/modules/forms/center/routes/center.routes.ts @@ -4,9 +4,9 @@ import CenterController from "../controller/center.controller"; const CenterRouter = Router(); CenterRouter.post("/", CenterController.create); // ایجاد -CenterRouter.get("/", CenterController.getAll); // لیست همه -CenterRouter.get("/:id", CenterController.getById); // مشاهده یکی -CenterRouter.put("/:id", CenterController.update); // ویرایش -CenterRouter.delete("/:id", CenterController.delete); // حذف +CenterRouter.get("/all", CenterController.getAll); // لیست همه +CenterRouter.get("/get/:id", CenterController.getById); // مشاهده یکی +CenterRouter.put("/update/:id", CenterController.update); // ویرایش +CenterRouter.delete("/delete/:id", CenterController.delete); // حذف export default CenterRouter; diff --git a/src/modules/forms/center/service/center.service.ts b/src/modules/forms/center/service/center.service.ts index b0548ea..2750e93 100644 --- a/src/modules/forms/center/service/center.service.ts +++ b/src/modules/forms/center/service/center.service.ts @@ -1,6 +1,4 @@ -import createHttpError from "http-errors"; import { Controller } from "../../../../core/controller/main.controller"; -import { GlobalErrorMessages } from "../../../../core/messages/errors"; import { Center } from "../../../../models/Center"; import { JobCategory } from "../../../../models/JobCategory";