Merge branch 'dev' into staging

This commit is contained in:
Vins 2024-04-04 11:41:29 +02:00
commit 568257f6b9
2 changed files with 60 additions and 49 deletions

View File

@ -15,7 +15,13 @@ import { EType } from "le-coffre-resources/dist/Admin/Subscription";
@Controller()
@Service()
export default class UserController extends ApiController {
constructor(private authService: AuthService, private idNotService: IdNotService, private userService: UsersService, private subscriptionsService: SubscriptionsService, private seatsService: SeatsService) {
constructor(
private authService: AuthService,
private idNotService: IdNotService,
private userService: UsersService,
private subscriptionsService: SubscriptionsService,
private seatsService: SeatsService,
) {
super();
}
@ -49,7 +55,7 @@ export default class UserController extends ApiController {
//Whitelist feature
//Get user with contact
const prismaUser = await this.userService.getByUid(user.uid, {contact: true });
const prismaUser = await this.userService.getByUid(user.uid, { contact: true, role: true });
if (!prismaUser) {
this.httpNotFoundRequest(response, "user not found");
@ -63,8 +69,10 @@ export default class UserController extends ApiController {
this.httpUnauthorized(response, "Email not found");
return;
}
let isSubscribed = false;
if (userHydrated.role?.name === "admin") {
isSubscribed = true;
} else {
const subscriptions = await this.subscriptionsService.get({ where: { office_uid: userHydrated.office_membership?.uid } });
if (!subscriptions || subscriptions.length === 0 || subscriptions[0]?.status === ESubscriptionStatus.INACTIVE) {
@ -75,14 +83,14 @@ export default class UserController extends ApiController {
if (subscriptions[0]?.type === EType.Unlimited) {
isSubscribed = true;
}
else{
const hasSeat = await this.subscriptionsService.get({ where: {status: ESubscriptionStatus.ACTIVE, seats: {some : {user_uid : userHydrated.uid }} } });
} else {
const hasSeat = await this.subscriptionsService.get({
where: { status: ESubscriptionStatus.ACTIVE, seats: { some: { user_uid: userHydrated.uid } } },
});
if (hasSeat && hasSeat.length > 0) {
isSubscribed = true;
}
else {
} else {
const nbMaxSeats = subscriptions[0]!.nb_seats;
const nbCurrentSeats = await this.seatsService.get({ where: { subscription_uid: subscriptions[0]!.uid } });
@ -96,6 +104,7 @@ export default class UserController extends ApiController {
}
}
}
}
if (!isSubscribed) {
this.httpUnauthorized(response, "User not subscribed");
@ -105,7 +114,6 @@ export default class UserController extends ApiController {
//Check if user is whitelisted
// const isWhitelisted = await this.whitelistService.getByEmail(userHydrated.contact!.email);
//When we'll switch to idNotId whitelisting
// const isWhitelisted = await this.userWhitelistService.getByIdNotId(user.idNot);
@ -115,7 +123,6 @@ export default class UserController extends ApiController {
// return;
// }
await this.idNotService.updateOffice(user.office_uid);
const payload = await this.authService.getUserJwtPayload(user.idNot);

View File

@ -147,7 +147,7 @@ export default class IdNotService extends BaseService {
case EIdnotRole.SUPPLEANT:
return (await this.rolesService.get({ where: { name: "notary" } }))[0]!;
case EIdnotRole.ADMINISTRATEUR:
return (await this.rolesService.get({ where: { name: "notary" } }))[0]!;
return (await this.rolesService.get({ where: { name: "admin" } }))[0]!;
case EIdnotRole.CURATEUR:
return (await this.rolesService.get({ where: { name: "notary" } }))[0]!;
default:
@ -346,6 +346,10 @@ export default class IdNotService extends BaseService {
// }
const role = await this.getRole(userData.typeLien.name);
console.log(role);
console.log(userData.typeLien);
const userToAdd = {
idNot: decodedToken.sub,