Merge branch 'staging' into preprod

This commit is contained in:
Vins 2024-02-28 12:06:52 +01:00
commit fadc3b3595
4 changed files with 23 additions and 9 deletions

View File

@ -25,6 +25,7 @@ export default class UserController extends ApiController {
protected async getUserInfosFromIdnot(req: Request, response: Response) { protected async getUserInfosFromIdnot(req: Request, response: Response) {
try { try {
const code = req.params["code"]; const code = req.params["code"];
if (!code) throw new Error("code is required"); if (!code) throw new Error("code is required");
const idNotToken = await this.idNotService.getIdNotToken(code); const idNotToken = await this.idNotService.getIdNotToken(code);
@ -34,16 +35,19 @@ export default class UserController extends ApiController {
return; return;
} }
const user = await this.idNotService.getOrCreateUser(idNotToken); const user = await this.idNotService.getOrCreateUser(idNotToken);
if(!user) { if(!user) {
this.httpUnauthorized(response, "Email not found"); this.httpUnauthorized(response, "Email not found");
return; return;
} }
await this.idNotService.updateUser(user.uid);
//Whitelist feature //Whitelist feature
//Get user with contact //Get user with contact
const prismaUser = await this.userService.getByUid(user.uid, {contact: true }); const prismaUser = await this.userService.getByUid(user.uid, {contact: true });
if (!prismaUser) { if (!prismaUser) {
this.httpNotFoundRequest(response, "user not found"); this.httpNotFoundRequest(response, "user not found");
return; return;
@ -58,15 +62,16 @@ export default class UserController extends ApiController {
} }
//Check if user is whitelisted //Check if user is whitelisted
const isWhitelisted = await this.whitelistService.getByEmail(userHydrated.contact!.email);
const isWhitelisted = await this.whitelistService.getByEmail(userHydrated.contact!.email);
//If not whitelisted, return 409 Not whitelisted //If not whitelisted, return 409 Not whitelisted
if (!isWhitelisted) { if (!isWhitelisted || isWhitelisted.length === 0) {
this.httpNotWhitelisted(response); this.httpNotWhitelisted(response);
return; return;
} }
await this.idNotService.updateUser(user.uid);
await this.idNotService.updateOffice(user.office_uid); await this.idNotService.updateOffice(user.office_uid);
const payload = await this.authService.getUserJwtPayload(user.idNot); const payload = await this.authService.getUserJwtPayload(user.idNot);

View File

@ -21,7 +21,10 @@ export default class ContactRepository extends BaseRepository {
public async findSomeByEmail(email: string): Promise<(Contacts & {customers: Customers | null})[] | null> { public async findSomeByEmail(email: string): Promise<(Contacts & {customers: Customers | null})[] | null> {
return this.model.findMany({ return this.model.findMany({
where: { where: {
email: email, email: {
equals: email,
mode: "insensitive"
}
}, },
include: { customers: true } include: { customers: true }
}); });

View File

@ -27,9 +27,12 @@ export default class WhitelistRepository extends BaseRepository {
* @description : find unique by email * @description : find unique by email
*/ */
public async findOneByEmail(email: string) { public async findOneByEmail(email: string) {
return this.model.findUnique({ return this.model.findMany({
where: { where: {
email: email, email: {
equals: email,
mode: "insensitive"
}
}, },
}); });
} }

View File

@ -91,7 +91,7 @@ export default class CustomersService extends BaseService {
public async verifyEmail2FASms(email: string): Promise<{ customer: Customer; totpCode: TotpCodesResource } | null> { public async verifyEmail2FASms(email: string): Promise<{ customer: Customer; totpCode: TotpCodesResource } | null> {
// 1: Check if the customer exists // 1: Check if the customer exists
const customer = await this.getByEmail(email); const customer = await this.getByEmail(email);
if (!customer) return null; if (!customer) return null;
const now = new Date().getTime(); const now = new Date().getTime();
const customerHydrated = Customer.hydrate<Customer>(customer); const customerHydrated = Customer.hydrate<Customer>(customer);
@ -316,7 +316,10 @@ export default class CustomersService extends BaseService {
return this.customerRepository.findOne({ return this.customerRepository.findOne({
where: { where: {
contact: { contact: {
email, email:{
equals: email,
mode: 'insensitive'
}
}, },
}, },
include: { include: {