Merge branch 'idNotWhitelist' into subscriptions
This commit is contained in:
commit
1bcb1dca6f
@ -38,7 +38,7 @@ export default class UserController extends ApiController {
|
|||||||
const user = await this.idNotService.getOrCreateUser(idNotToken);
|
const user = await this.idNotService.getOrCreateUser(idNotToken);
|
||||||
|
|
||||||
if(!user) {
|
if(!user) {
|
||||||
this.httpUnauthorized(response, "Email not found");
|
this.httpUnauthorized(response, "User not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,8 +62,10 @@ 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
|
||||||
|
// const isWhitelisted = await this.userWhitelistService.getByIdNotId(user.idNot);
|
||||||
|
|
||||||
//If not whitelisted, return 409 Not whitelisted
|
//If not whitelisted, return 409 Not whitelisted
|
||||||
if (!isWhitelisted || isWhitelisted.length === 0) {
|
if (!isWhitelisted || isWhitelisted.length === 0) {
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "user_whitelist" (
|
||||||
|
"uid" TEXT NOT NULL,
|
||||||
|
"idNot" VARCHAR(255) NOT NULL,
|
||||||
|
"active" BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updated_at" TIMESTAMP(3),
|
||||||
|
|
||||||
|
CONSTRAINT "user_whitelist_pkey" PRIMARY KEY ("uid")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE UNIQUE INDEX "user_whitelist_uid_key" ON "user_whitelist"("uid");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE UNIQUE INDEX "user_whitelist_idNot_key" ON "user_whitelist"("idNot");
|
@ -81,6 +81,15 @@ model Whitelist {
|
|||||||
@@map("whitelist")
|
@@map("whitelist")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model UserWhitelist {
|
||||||
|
uid String @id @unique @default(uuid())
|
||||||
|
idNot String @unique @db.VarChar(255)
|
||||||
|
active Boolean @default(true)
|
||||||
|
created_at DateTime? @default(now())
|
||||||
|
updated_at DateTime? @updatedAt
|
||||||
|
@@map("user_whitelist")
|
||||||
|
}
|
||||||
|
|
||||||
model Offices {
|
model Offices {
|
||||||
uid String @id @unique @default(uuid())
|
uid String @id @unique @default(uuid())
|
||||||
idNot String @unique @db.VarChar(255)
|
idNot String @unique @db.VarChar(255)
|
||||||
|
39
src/common/repositories/UserWhitelistRepository.ts
Normal file
39
src/common/repositories/UserWhitelistRepository.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import Database from "@Common/databases/database";
|
||||||
|
import BaseRepository from "@Repositories/BaseRepository";
|
||||||
|
import { Service } from "typedi";
|
||||||
|
import { Prisma } from "prisma/prisma-client";
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export default class UserWhitelistRepository extends BaseRepository {
|
||||||
|
constructor(private database: Database) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
protected get model() {
|
||||||
|
return this.database.getClient().userWhitelist;
|
||||||
|
}
|
||||||
|
protected get instanceDb() {
|
||||||
|
return this.database.getClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Find many whitelist
|
||||||
|
*/
|
||||||
|
public async findMany(query: Prisma.UserWhitelistFindManyArgs) {
|
||||||
|
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||||
|
return this.model.findMany(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : find unique by email
|
||||||
|
*/
|
||||||
|
public async findOneByIdNotId(idNotId: string) {
|
||||||
|
return this.model.findMany({
|
||||||
|
where: {
|
||||||
|
idNot: idNotId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
14
src/services/common/UserWhitelistService/WhitelistService.ts
Normal file
14
src/services/common/UserWhitelistService/WhitelistService.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import UserWhitelistRepository from "@Repositories/UserWhitelistRepository";
|
||||||
|
import BaseService from "@Services/BaseService";
|
||||||
|
import { Service } from "typedi";
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export default class UserWhitelistService extends BaseService {
|
||||||
|
constructor(private userWhitelistRepository: UserWhitelistRepository) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getByIdNotId(idNotId: string): Promise<any> {
|
||||||
|
return this.userWhitelistRepository.findOneByIdNotId(idNotId);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user