fix(user): make email optional when creating and updating

This commit is contained in:
avicenan
2026-06-01 09:45:00 +09:00
parent 9443e8fb82
commit 9eb3ae2545
2 changed files with 17 additions and 8 deletions

View File

@ -1,5 +1,5 @@
import axios from "axios"; 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 exceljs from "exceljs";
import { NextFunction, Response } from "express"; import { NextFunction, Response } from "express";
import { Request } from "express-jwt"; import { Request } from "express-jwt";
@ -15,6 +15,7 @@ import fileUpload from "express-fileupload";
import { v4 as uuidv4 } from "uuid"; import { v4 as uuidv4 } from "uuid";
import config from "../../config/stag.json"; import config from "../../config/stag.json";
import { IsNull } from "typeorm"; import { IsNull } from "typeorm";
const log: Logger<ILogObj> = new Logger({ const log: Logger<ILogObj> = new Logger({
name: "[UserController]", name: "[UserController]",
type: "pretty", type: "pretty",
@ -89,13 +90,13 @@ export class UserController {
const res_count = userRepository const res_count = userRepository
.createQueryBuilder("User") .createQueryBuilder("User")
.leftJoin("User.roles", "roles") .leftJoin("User.roles", "roles")
.where(whereAttr, whereVal); .where(whereAttr, whereVal);
const subquery = userRepository const subquery = userRepository
.createQueryBuilder("User") .createQueryBuilder("User")
.select("User.id", "id") .select("User.id", "id")
.leftJoin("User.roles", "roles") .leftJoin("User.roles", "roles")
.where(whereAttr, whereVal) .where(whereAttr, whereVal)
.orderBy("User." + param.order_field, param.order_direction) .orderBy("User." + param.order_field, param.order_direction)
.offset(offset) .offset(offset)
@ -488,7 +489,7 @@ export class UserController {
try { try {
const schema = Joi.object().keys({ 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"), 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"), password: Joi.string().pattern(new RegExp("^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$")).min(8).required().label("Password"),
retype_password: Joi.ref("password"), retype_password: Joi.ref("password"),
@ -895,7 +896,7 @@ export class UserController {
try { try {
const schema = Joi.object().keys({ const schema = Joi.object().keys({
id: Joi.string().uuid().required().label("ID"), 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"), username: Joi.string().max(64).required().label("Username"),
password: Joi.string().allow("").optional().label("Password"), password: Joi.string().allow("").optional().label("Password"),
name: Joi.string().max(64).required().label("Name"), name: Joi.string().max(64).required().label("Name"),
@ -920,7 +921,7 @@ export class UserController {
// await UserController.deleteFile(oldFilePath); // await UserController.deleteFile(oldFilePath);
// } // }
// } // }
data.profile_picture = param.profile_picture || data.profile_picture; data.profile_picture = param.profile_picture || data.profile_picture;
data.name = param.name; data.name = param.name;
data.username = param.username; data.username = param.username;
@ -1127,6 +1128,14 @@ export class UserController {
where: { id: param.id }, 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) { if (detail != null) {
const data = { const data = {
...detail, ...detail,

View File

@ -22,7 +22,7 @@ const doc = {
}, },
user: { user: {
$employee_id: "EMP001", $employee_id: "EMP001",
$email: "admin@gmail.com", email: "admin@gmail.com",
$username: "admin", $username: "admin",
$password: "12345aA!", $password: "12345aA!",
$retype_password: "12345aA!", $retype_password: "12345aA!",
@ -35,7 +35,7 @@ const doc = {
$status: "Y" $status: "Y"
}, },
user_profile: { user_profile: {
$email: "admin@gmail.com", email: "admin@gmail.com",
$username: "admin", $username: "admin",
$name: "Administrator" $name: "Administrator"
}, },