This commit is contained in:
Vins 2024-04-24 11:26:54 +02:00
parent e4f40336c7
commit 7d16243f32

View File

@ -46,8 +46,7 @@ export default class UserController extends ApiController {
return; return;
} }
const user = await this.idNotService.getOrCreateUser(idNotToken); const user = await this.idNotService.getOrCreateUser(idNotToken);
console.log(user);
if (!user) { if (!user) {
this.httpUnauthorized(response, "User not found"); this.httpUnauthorized(response, "User not found");
@ -58,38 +57,29 @@ 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, office_membership: true});
console.log(prismaUser);
if (!prismaUser) { if (!prismaUser) {
this.httpNotFoundRequest(response, "user not found"); this.httpNotFoundRequest(response, "user not found");
return; return;
} }
//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" });
console.log(userHydrated);
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 = 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 } });
console.log(subscriptions);
if (!subscriptions || subscriptions.length === 0 || subscriptions[0]?.status === ESubscriptionStatus.INACTIVE) {
if (!subscriptions || subscriptions.length === 0 || subscriptions[0]?.status === ESubscriptionStatus.INACTIVE) {
console.log("no subscription");
isSubscribed = false; isSubscribed = false;
} else if (subscriptions[0]?.type === EType.Unlimited) { }
console.log("unlimited subscription"); else if (subscriptions[0]?.type === EType.Unlimited) {
isSubscribed = true; isSubscribed = true;
} else { } else {
console.log("Seats");
const hasSeat = await this.subscriptionsService.get({ const hasSeat = await this.subscriptionsService.get({
where: { status: ESubscriptionStatus.ACTIVE, seats: { some: { user_uid: userHydrated.uid } } }, 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); await this.idNotService.updateOffice(user.office_uid);
const payload = await this.authService.getUserJwtPayload(user.idNot); const payload = await this.authService.getUserJwtPayload(user.idNot);
if (!payload) return; 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 } });
if ((!isSubscribed && userHydrated.role?.name === "admin") || userHydrated.role?.name === "super-admin") {
const manageSubscriptionRulesEntity = await this.rulesGroupsService.get({ const manageSubscriptionRules = RulesGroup.hydrateArray<RulesGroup>(manageSubscriptionRulesEntity, { strategy: "excludeAll" });
where: { uid: "94343601-04c8-44ef-afb9-3047597528a9" }, if(!manageSubscriptionRules[0]) return;
include: { rules: true },
}); payload.rules = manageSubscriptionRules[0].rules!.map((rule) => rule.name) || [];
console.log(manageSubscriptionRulesEntity);
isSubscribed = true;
const manageSubscriptionRules = RulesGroup.hydrateArray<RulesGroup>(manageSubscriptionRulesEntity, {
strategy: "excludeAll",
});
if (!manageSubscriptionRules[0]) return;
payload.rules = manageSubscriptionRules[0].rules!.map((rule) => rule.name) || [];
console.log(payload);
isSubscribed = true;
} }
if (!isSubscribed) { if (!isSubscribed) {