allow admin to connect
This commit is contained in:
parent
fc75a78fff
commit
832102d1fd
@ -15,7 +15,13 @@ import { EType } from "le-coffre-resources/dist/Admin/Subscription";
|
|||||||
@Controller()
|
@Controller()
|
||||||
@Service()
|
@Service()
|
||||||
export default class UserController extends ApiController {
|
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();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,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 });
|
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,8 +69,10 @@ export default class UserController extends ApiController {
|
|||||||
this.httpUnauthorized(response, "Email not found");
|
this.httpUnauthorized(response, "Email not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let isSubscribed = false;
|
let isSubscribed = false;
|
||||||
|
if (userHydrated.role?.name === "admin") {
|
||||||
|
isSubscribed = true;
|
||||||
|
} else {
|
||||||
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) {
|
||||||
@ -75,14 +83,14 @@ export default class UserController extends ApiController {
|
|||||||
|
|
||||||
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({ where: {status: ESubscriptionStatus.ACTIVE, seats: {some : {user_uid : userHydrated.uid }} } });
|
where: { status: ESubscriptionStatus.ACTIVE, seats: { some: { user_uid: userHydrated.uid } } },
|
||||||
|
});
|
||||||
|
|
||||||
if (hasSeat && hasSeat.length > 0) {
|
if (hasSeat && hasSeat.length > 0) {
|
||||||
isSubscribed = true;
|
isSubscribed = true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
const nbMaxSeats = subscriptions[0]!.nb_seats;
|
const nbMaxSeats = subscriptions[0]!.nb_seats;
|
||||||
|
|
||||||
const nbCurrentSeats = await this.seatsService.get({ where: { subscription_uid: subscriptions[0]!.uid } });
|
const nbCurrentSeats = await this.seatsService.get({ where: { subscription_uid: subscriptions[0]!.uid } });
|
||||||
@ -96,6 +104,7 @@ export default class UserController extends ApiController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!isSubscribed) {
|
if (!isSubscribed) {
|
||||||
this.httpUnauthorized(response, "User not subscribed");
|
this.httpUnauthorized(response, "User not subscribed");
|
||||||
@ -105,7 +114,6 @@ export default class UserController extends ApiController {
|
|||||||
//Check if user is whitelisted
|
//Check if user is whitelisted
|
||||||
// const isWhitelisted = await this.whitelistService.getByEmail(userHydrated.contact!.email);
|
// const isWhitelisted = await this.whitelistService.getByEmail(userHydrated.contact!.email);
|
||||||
|
|
||||||
|
|
||||||
//When we'll switch to idNotId whitelisting
|
//When we'll switch to idNotId whitelisting
|
||||||
// const isWhitelisted = await this.userWhitelistService.getByIdNotId(user.idNot);
|
// const isWhitelisted = await this.userWhitelistService.getByIdNotId(user.idNot);
|
||||||
|
|
||||||
@ -115,7 +123,6 @@ export default class UserController extends ApiController {
|
|||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
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);
|
||||||
|
@ -147,7 +147,7 @@ export default class IdNotService extends BaseService {
|
|||||||
case EIdnotRole.SUPPLEANT:
|
case EIdnotRole.SUPPLEANT:
|
||||||
return (await this.rolesService.get({ where: { name: "notary" } }))[0]!;
|
return (await this.rolesService.get({ where: { name: "notary" } }))[0]!;
|
||||||
case EIdnotRole.ADMINISTRATEUR:
|
case EIdnotRole.ADMINISTRATEUR:
|
||||||
return (await this.rolesService.get({ where: { name: "notary" } }))[0]!;
|
return (await this.rolesService.get({ where: { name: "admin" } }))[0]!;
|
||||||
case EIdnotRole.CURATEUR:
|
case EIdnotRole.CURATEUR:
|
||||||
return (await this.rolesService.get({ where: { name: "notary" } }))[0]!;
|
return (await this.rolesService.get({ where: { name: "notary" } }))[0]!;
|
||||||
default:
|
default:
|
||||||
@ -346,6 +346,10 @@ export default class IdNotService extends BaseService {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
const role = await this.getRole(userData.typeLien.name);
|
const role = await this.getRole(userData.typeLien.name);
|
||||||
|
console.log(role);
|
||||||
|
console.log(userData.typeLien);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const userToAdd = {
|
const userToAdd = {
|
||||||
idNot: decodedToken.sub,
|
idNot: decodedToken.sub,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user