Merge branch 'preprod' into staging

This commit is contained in:
Vins 2024-07-23 16:15:10 +02:00
commit ff10fbd69c

View File

@ -31,7 +31,8 @@ export default class UserController extends ApiController {
@Post("/api/v1/idnot/user/:code") @Post("/api/v1/idnot/user/:code")
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);
@ -41,7 +42,7 @@ 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, "User not found"); this.httpUnauthorized(response, "User not found");
@ -52,7 +53,7 @@ export default class UserController extends ApiController {
//Whitelist feature //Whitelist feature
//Get user with contact //Get user with contact
const prismaUser = await this.userService.getByUid(user.uid, { contact: true, role: true, office_membership: true }); const prismaUser = await this.userService.getByUid(user.uid, { contact: true, role: true, office_membership: true });
if (!prismaUser) { if (!prismaUser) {
this.httpNotFoundRequest(response, "user not found"); this.httpNotFoundRequest(response, "user not found");
@ -60,13 +61,15 @@ export default class UserController extends ApiController {
} }
//Hydrate user to be able to use his contact //Hydrate user to be able to use his contact
const userHydrated = User.hydrate<User>(prismaUser, { strategy: "excludeAll" }); const userHydrated = User.hydrate<User>(prismaUser, { strategy: "excludeAll" });
if (!userHydrated.contact?.email || userHydrated.contact?.email === "") { if (!userHydrated.contact?.email || userHydrated.contact?.email === "") {
this.httpUnauthorized(response, "Email not found"); this.httpUnauthorized(response, "Email not found");
return; return;
} }
let isSubscribed = await this.subscriptionsService.isUserSubscribed(user.uid, userHydrated.office_membership?.uid!); let isSubscribed = await this.subscriptionsService.isUserSubscribed(user.uid, userHydrated.office_membership?.uid!);
//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);
@ -103,7 +106,7 @@ export default class UserController extends ApiController {
isSubscribed = true; isSubscribed = true;
} }
if (!isSubscribed) { if (!isSubscribed) {
this.httpUnauthorized(response, "User not subscribed"); this.httpUnauthorized(response, "User not subscribed");
return; return;
} }