Skip to content

Commit

Permalink
Merge pull request #39 from Callgent/user-as-a-service
Browse files Browse the repository at this point in the history
docs: rename mailHost
  • Loading branch information
Jamesp918 authored Jun 24, 2024
2 parents f6de859 + 8063ebb commit 0096ec3
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class UsersService {
async registerUserFromIdentity(
ui: CreateUserIdentityDto & { email_verified?: boolean },
) {
const [mailName, mailHost] = ui.email?.split('@') || [];
const [mailName, emailHost] = ui.email?.split('@') || [];
ui.name || (ui.name = mailName) || (ui.name = `${ui.provider}@${ui.uid}`);

const prisma = this.txHost.tx as PrismaClient;
Expand Down Expand Up @@ -134,16 +134,16 @@ export class UsersService {
}
} else {
// register tenant from email host
const tenant = await this.registerTenant(mailHost);
const tenant = await this.registerTenant(emailHost);

if (tenant.deletedAt)
throw new ForbiddenException(
mailHost,
emailHost,
'Sorry, current account has no access to our services',
);
if (!(tenant.statusCode > 0))
throw new ForbiddenException(
mailHost,
emailHost,
`Sorry, current account is in ${
tenant.statusCode == 0 ? 'pending' : 'inactive'
} statusCode, please try again later.`,
Expand Down Expand Up @@ -191,16 +191,16 @@ export class UsersService {
* @returns new or existing tenant, even invalid
*/
@Transactional()
async registerTenant(mailHost: string) {
mailHost || (mailHost = undefined);
async registerTenant(emailHost: string) {
emailHost || (emailHost = undefined);
const prisma = this.txHost.tx as PrismaClient;

let tenant =
mailHost &&
emailHost &&
(await prisma.tenant.findFirst({
where: {
AND: {
mailHost,
emailHost,
OR: [{ deletedAt: null }, { deletedAt: { not: null } }],
},
},
Expand All @@ -211,8 +211,8 @@ export class UsersService {
tenant = await prisma.tenant.create({
data: {
uuid: Utils.uuid(),
mailHost,
name: mailHost,
emailHost,
name: emailHost,
type: 1,
statusCode: 1, // active by default
},
Expand Down

0 comments on commit 0096ec3

Please sign in to comment.