Fixed login

This commit is contained in:
Vins 2024-04-12 16:11:00 +02:00
parent 743934120e
commit 79edaaefa4

View File

@ -37,14 +37,14 @@ export default class UserController extends ApiController {
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);
if (!idNotToken) { if (!idNotToken) {
this.httpValidationError(response, "IdNot token undefined"); this.httpValidationError(response, "IdNot token undefined");
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");
@ -55,7 +55,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 }); const prismaUser = await this.userService.getByUid(user.uid, { contact: true, role: true });
if (!prismaUser) { if (!prismaUser) {
this.httpNotFoundRequest(response, "user not found"); this.httpNotFoundRequest(response, "user not found");
@ -63,7 +63,7 @@ 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");
@ -71,14 +71,12 @@ export default class UserController extends ApiController {
} }
let isSubscribed = false; let isSubscribed = false;
const subscriptions = await this.subscriptionsService.get({ where: { office_uid: userHydrated.office_membership?.uid } }); const subscriptions = await this.subscriptionsService.get({ where: { office_uid: userHydrated.office_membership?.uid } });
if (!subscriptions || subscriptions.length === 0 || subscriptions[0]?.status === ESubscriptionStatus.INACTIVE) { if (!subscriptions || subscriptions.length === 0 || subscriptions[0]?.status === ESubscriptionStatus.INACTIVE) {
isSubscribed = false; isSubscribed = false;
return;
} }
else if (subscriptions[0]?.type === EType.Unlimited) {
if (subscriptions[0]?.type === EType.Unlimited) {
isSubscribed = true; isSubscribed = true;
} else { } else {
const hasSeat = await this.subscriptionsService.get({ const hasSeat = await this.subscriptionsService.get({