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

View File

@ -47,7 +47,6 @@ export default class UserController extends ApiController {
}
const user = await this.idNotService.getOrCreateUser(idNotToken);
console.log(user);
if (!user) {
this.httpUnauthorized(response, "User not found");
@ -58,17 +57,14 @@ 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<User>(prismaUser, { strategy: "excludeAll" });
console.log(userHydrated);
if (!userHydrated.contact?.email || userHydrated.contact?.email === "") {
this.httpUnauthorized(response, "Email not found");
@ -77,19 +73,13 @@ export default class UserController extends ApiController {
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");
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");
const hasSeat = await this.subscriptionsService.get({
where: { status: ESubscriptionStatus.ACTIVE, seats: { some: { user_uid: userHydrated.uid } } },
});
@ -128,22 +118,13 @@ export default class UserController extends ApiController {
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 } });
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<RulesGroup>(manageSubscriptionRulesEntity, {
strategy: "excludeAll",
});
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;
}