fix: dashboard sidebar expanding.

This commit is contained in:
a.bouhuolia
2021-04-19 18:34:02 +02:00
parent c6aca4ecfa
commit f29c1b6cec
27 changed files with 178 additions and 230 deletions

View File

@@ -223,13 +223,14 @@ export default class UsersController extends BaseController{
* @param {NextFunction} next
*/
catchServiceErrors(error: Error, req: Request, res: Response, next: NextFunction) {
if (error instanceof ServiceErrors) {
const errorReasons = [];
if (error.errorType === 'EMAIL_ALREADY_EXISTS') {
if (error.hasType('EMAIL_ALREADY_EXISTS')) {
errorReasons.push({ type: 'EMAIL_ALREADY_EXIST', code: 100 });
}
if (error.errorType === 'PHONE_NUMBER_ALREADY_EXIST') {
if (error.hasType('PHONE_NUMBER_ALREADY_EXIST')) {
errorReasons.push({ type: 'PHONE_NUMBER_ALREADY_EXIST', code: 200 });
}
if (errorReasons.length > 0) {

View File

@@ -2,6 +2,7 @@ import TenancyService from 'services/Tenancy/TenancyService';
import { Inject, Service } from 'typedi';
import { ServiceError, ServiceErrors } from 'exceptions';
import { ISystemUser, ISystemUserDTO } from 'interfaces';
import { SystemUser } from 'system/models';
const ERRORS = {
CANNOT_DELETE_LAST_USER: 'CANNOT_DELETE_LAST_USER',
@@ -38,20 +39,20 @@ export default class UsersService {
): Promise<ISystemUser> {
const { systemUserRepository } = this.repositories;
const userByEmail = await systemUserRepository.findOne({
email: userDTO.email,
id: userId,
});
const userByPhoneNumber = await systemUserRepository.findOne({
phoneNumber: userDTO.phoneNumber,
id: userId,
});
const userByEmail = await SystemUser.query()
.where('email', userDTO.email)
.whereNot('id', userId);
const userByPhoneNumber = await SystemUser.query()
.where('phone_number', userDTO.phoneNumber)
.whereNot('id', userId);
const serviceErrors: ServiceError[] = [];
if (userByEmail) {
if (userByEmail.length > 0) {
serviceErrors.push(new ServiceError(ERRORS.EMAIL_ALREADY_EXISTS));
}
if (userByPhoneNumber) {
if (userByPhoneNumber.length > 0) {
serviceErrors.push(new ServiceError(ERRORS.PHONE_NUMBER_ALREADY_EXIST));
}
if (serviceErrors.length > 0) {