Added log
This commit is contained in:
parent
9d6282a81d
commit
c87fa70c74
@ -32,10 +32,14 @@ export default class UserController extends ApiController {
|
|||||||
protected async getUserInfosFromIdnot(req: Request, response: Response) {
|
protected async getUserInfosFromIdnot(req: Request, response: Response) {
|
||||||
try {
|
try {
|
||||||
const code = req.params["code"];
|
const code = req.params["code"];
|
||||||
|
console.log("code", code);
|
||||||
|
|
||||||
|
|
||||||
if (!code) throw new Error("code is required");
|
if (!code) throw new Error("code is required");
|
||||||
|
|
||||||
const idNotToken = await this.idNotService.getIdNotToken(code);
|
const idNotToken = await this.idNotService.getIdNotToken(code);
|
||||||
|
console.log("idNotToken", idNotToken);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!idNotToken) {
|
if (!idNotToken) {
|
||||||
@ -44,6 +48,8 @@ export default class UserController extends ApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const user = await this.idNotService.getOrCreateUser(idNotToken);
|
const user = await this.idNotService.getOrCreateUser(idNotToken);
|
||||||
|
console.log("user", user);
|
||||||
|
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
this.httpUnauthorized(response, "User not found");
|
this.httpUnauthorized(response, "User not found");
|
||||||
@ -55,6 +61,8 @@ 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, office_membership: true });
|
const prismaUser = await this.userService.getByUid(user.uid, { contact: true, role: true, office_membership: true });
|
||||||
|
console.log("prismaUser", prismaUser);
|
||||||
|
|
||||||
|
|
||||||
if (!prismaUser) {
|
if (!prismaUser) {
|
||||||
this.httpNotFoundRequest(response, "user not found");
|
this.httpNotFoundRequest(response, "user not found");
|
||||||
@ -63,12 +71,16 @@ export default class UserController extends ApiController {
|
|||||||
|
|
||||||
//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", 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 = await this.subscriptionsService.isUserSubscribed(user.uid, userHydrated.office_membership?.uid!);
|
let isSubscribed = await this.subscriptionsService.isUserSubscribed(user.uid, userHydrated.office_membership?.uid!);
|
||||||
|
console.log("isSubscribed", isSubscribed);
|
||||||
|
|
||||||
|
|
||||||
//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);
|
||||||
@ -85,9 +97,13 @@ 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);
|
||||||
|
console.log("payload", payload);
|
||||||
|
|
||||||
if (!payload) return;
|
if (!payload) return;
|
||||||
|
|
||||||
if (!isSubscribed && (userHydrated.role?.name === "admin" || userHydrated.role?.name === "super-admin")) {
|
if (!isSubscribed && (userHydrated.role?.name === "admin" || userHydrated.role?.name === "super-admin")) {
|
||||||
|
console.log("userHydrated.role", userHydrated.role);
|
||||||
|
|
||||||
const manageSubscriptionRulesEntity = await this.rulesGroupsService.get({
|
const manageSubscriptionRulesEntity = await this.rulesGroupsService.get({
|
||||||
where: { uid: "94343601-04c8-44ef-afb9-3047597528a9" },
|
where: { uid: "94343601-04c8-44ef-afb9-3047597528a9" },
|
||||||
include: { rules: true },
|
include: { rules: true },
|
||||||
@ -104,6 +120,8 @@ export default class UserController extends ApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isSubscribed) {
|
if (!isSubscribed) {
|
||||||
|
console.log("User not subscribed");
|
||||||
|
|
||||||
this.httpUnauthorized(response, "User not subscribed");
|
this.httpUnauthorized(response, "User not subscribed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user