diff --git a/src/app/api/idnot/UserController.ts b/src/app/api/idnot/UserController.ts index f8c43ba2..dc749489 100644 --- a/src/app/api/idnot/UserController.ts +++ b/src/app/api/idnot/UserController.ts @@ -46,8 +46,7 @@ export default class UserController extends ApiController { return; } - const user = await this.idNotService.getOrCreateUser(idNotToken); - console.log(user); + const user = await this.idNotService.getOrCreateUser(idNotToken); if (!user) { this.httpUnauthorized(response, "User not found"); @@ -58,38 +57,29 @@ export default class UserController extends ApiController { //Whitelist feature //Get user with contact - const prismaUser = await this.userService.getByUid(user.uid, { contact: true, role: true }); - console.log(prismaUser); + const prismaUser = await this.userService.getByUid(user.uid, { contact: true, role: true, office_membership: true}); if (!prismaUser) { this.httpNotFoundRequest(response, "user not found"); return; - } - + } //Hydrate user to be able to use his contact const userHydrated = User.hydrate(prismaUser, { strategy: "excludeAll" }); - console.log(userHydrated); - + if (!userHydrated.contact?.email || userHydrated.contact?.email === "") { this.httpUnauthorized(response, "Email not found"); return; } let isSubscribed = false; - const subscriptions = await this.subscriptionsService.get({ where: { office_uid: userHydrated.office_membership?.uid } }); - console.log(subscriptions); - - if (!subscriptions || subscriptions.length === 0 || subscriptions[0]?.status === ESubscriptionStatus.INACTIVE) { - console.log("no subscription"); - + const subscriptions = await this.subscriptionsService.get({ where: { office_uid: userHydrated.office_membership?.uid } }); + + if (!subscriptions || subscriptions.length === 0 || subscriptions[0]?.status === ESubscriptionStatus.INACTIVE) { isSubscribed = false; - } else if (subscriptions[0]?.type === EType.Unlimited) { - console.log("unlimited subscription"); - + } + else if (subscriptions[0]?.type === EType.Unlimited) { isSubscribed = true; - } else { - console.log("Seats"); - + } else { const hasSeat = await this.subscriptionsService.get({ where: { status: ESubscriptionStatus.ACTIVE, seats: { some: { user_uid: userHydrated.uid } } }, }); @@ -125,27 +115,18 @@ export default class UserController extends ApiController { await this.idNotService.updateOffice(user.office_uid); - const payload = await this.authService.getUserJwtPayload(user.idNot); - if (!payload) return; - - console.log(isSubscribed, userHydrated.role?.name); - - if ((!isSubscribed && userHydrated.role?.name === "admin") || userHydrated.role?.name === "super-admin") { - const manageSubscriptionRulesEntity = await this.rulesGroupsService.get({ - where: { uid: "94343601-04c8-44ef-afb9-3047597528a9" }, - include: { rules: true }, - }); - console.log(manageSubscriptionRulesEntity); - - const manageSubscriptionRules = RulesGroup.hydrateArray(manageSubscriptionRulesEntity, { - strategy: "excludeAll", - }); - if (!manageSubscriptionRules[0]) return; - - payload.rules = manageSubscriptionRules[0].rules!.map((rule) => rule.name) || []; - console.log(payload); - - isSubscribed = true; + const payload = await this.authService.getUserJwtPayload(user.idNot); + if(!payload) return; + + if(!isSubscribed && userHydrated.role?.name === "admin" || userHydrated.role?.name === "super-admin"){ + const manageSubscriptionRulesEntity = await this.rulesGroupsService.get({ where: { uid: "94343601-04c8-44ef-afb9-3047597528a9" }, include: { rules: true } }); + + const manageSubscriptionRules = RulesGroup.hydrateArray(manageSubscriptionRulesEntity, { strategy: "excludeAll" }); + if(!manageSubscriptionRules[0]) return; + + payload.rules = manageSubscriptionRules[0].rules!.map((rule) => rule.name) || []; + + isSubscribed = true; } if (!isSubscribed) {