From 9eb3ae25454f1969510c63388b5bbfa166e01d51 Mon Sep 17 00:00:00 2001 From: avicenan Date: Mon, 1 Jun 2026 09:45:00 +0900 Subject: [PATCH] fix(user): make email optional when creating and updating --- src/controllers/user.ts | 21 +++++++++++++++------ src/swagger/builder.js | 4 ++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/controllers/user.ts b/src/controllers/user.ts index f0c6bf3..a2c3dc0 100644 --- a/src/controllers/user.ts +++ b/src/controllers/user.ts @@ -1,5 +1,5 @@ import axios from "axios"; -import { HrmsEmployee, Paging, User, UserRefreshToken, UserRole } from "entity"; +import { HrmsEmployee, Paging, User, UserRefreshToken, UserRole, UserToRoom } from "entity"; import exceljs from "exceljs"; import { NextFunction, Response } from "express"; import { Request } from "express-jwt"; @@ -15,6 +15,7 @@ import fileUpload from "express-fileupload"; import { v4 as uuidv4 } from "uuid"; import config from "../../config/stag.json"; import { IsNull } from "typeorm"; + const log: Logger = new Logger({ name: "[UserController]", type: "pretty", @@ -89,13 +90,13 @@ export class UserController { const res_count = userRepository .createQueryBuilder("User") - .leftJoin("User.roles", "roles") + .leftJoin("User.roles", "roles") .where(whereAttr, whereVal); const subquery = userRepository .createQueryBuilder("User") .select("User.id", "id") - .leftJoin("User.roles", "roles") + .leftJoin("User.roles", "roles") .where(whereAttr, whereVal) .orderBy("User." + param.order_field, param.order_direction) .offset(offset) @@ -488,7 +489,7 @@ export class UserController { try { const schema = Joi.object().keys({ - email: Joi.string().email().max(64).optional().label("Email"), + email: Joi.string().email().max(64).allow("", null).optional().label("Email"), username: Joi.string().max(64).required().label("Username"), password: Joi.string().pattern(new RegExp("^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$")).min(8).required().label("Password"), retype_password: Joi.ref("password"), @@ -895,7 +896,7 @@ export class UserController { try { const schema = Joi.object().keys({ id: Joi.string().uuid().required().label("ID"), - email: Joi.string().email().max(64).required().label("Email"), + email: Joi.string().email().max(64).allow("", null).optional().label("Email"), username: Joi.string().max(64).required().label("Username"), password: Joi.string().allow("").optional().label("Password"), name: Joi.string().max(64).required().label("Name"), @@ -920,7 +921,7 @@ export class UserController { // await UserController.deleteFile(oldFilePath); // } // } - + data.profile_picture = param.profile_picture || data.profile_picture; data.name = param.name; data.username = param.username; @@ -1127,6 +1128,14 @@ export class UserController { where: { id: param.id }, }); + // get all the rooms from the usertoroom + // const repo = OrmHelper.DB.getRepository(UserToRoom); + + // const rooms = await repo.createQueryBuilder('utr') + // .select('utr.id_room') + // .where('utr.user_id = :id', { id: param.id }) + // .getMany(); + if (detail != null) { const data = { ...detail, diff --git a/src/swagger/builder.js b/src/swagger/builder.js index 270b1e8..c4747ae 100644 --- a/src/swagger/builder.js +++ b/src/swagger/builder.js @@ -22,7 +22,7 @@ const doc = { }, user: { $employee_id: "EMP001", - $email: "admin@gmail.com", + email: "admin@gmail.com", $username: "admin", $password: "12345aA!", $retype_password: "12345aA!", @@ -35,7 +35,7 @@ const doc = { $status: "Y" }, user_profile: { - $email: "admin@gmail.com", + email: "admin@gmail.com", $username: "admin", $name: "Administrator" },