Compare commits

..

2 Commits

Author SHA1 Message Date
jamesgeorge007
263f8b3588 refactor: remove method chaining for consistency 2024-05-20 13:20:59 +05:30
nivedin
fc9f933905 fix: add previous value as optional 2024-05-17 00:00:13 +05:30
7 changed files with 22 additions and 36 deletions

View File

@@ -121,7 +121,6 @@ describe('AdminService', () => {
NOT: { NOT: {
inviteeEmail: { inviteeEmail: {
in: [dbAdminUsers[0].email], in: [dbAdminUsers[0].email],
mode: 'insensitive',
}, },
}, },
}, },
@@ -230,10 +229,7 @@ describe('AdminService', () => {
expect(mockPrisma.invitedUsers.deleteMany).toHaveBeenCalledWith({ expect(mockPrisma.invitedUsers.deleteMany).toHaveBeenCalledWith({
where: { where: {
inviteeEmail: { inviteeEmail: { in: [invitedUsers[0].inviteeEmail] },
in: [invitedUsers[0].inviteeEmail],
mode: 'insensitive',
},
}, },
}); });
expect(result).toEqualRight(true); expect(result).toEqualRight(true);

View File

@@ -89,17 +89,12 @@ export class AdminService {
adminEmail: string, adminEmail: string,
inviteeEmail: string, inviteeEmail: string,
) { ) {
if (inviteeEmail.toLowerCase() == adminEmail.toLowerCase()) { if (inviteeEmail == adminEmail) return E.left(DUPLICATE_EMAIL);
return E.left(DUPLICATE_EMAIL);
}
if (!validateEmail(inviteeEmail)) return E.left(INVALID_EMAIL); if (!validateEmail(inviteeEmail)) return E.left(INVALID_EMAIL);
const alreadyInvitedUser = await this.prisma.invitedUsers.findFirst({ const alreadyInvitedUser = await this.prisma.invitedUsers.findFirst({
where: { where: {
inviteeEmail: { inviteeEmail: inviteeEmail,
equals: inviteeEmail,
mode: 'insensitive',
},
}, },
}); });
if (alreadyInvitedUser != null) return E.left(USER_ALREADY_INVITED); if (alreadyInvitedUser != null) return E.left(USER_ALREADY_INVITED);
@@ -164,7 +159,7 @@ export class AdminService {
try { try {
await this.prisma.invitedUsers.deleteMany({ await this.prisma.invitedUsers.deleteMany({
where: { where: {
inviteeEmail: { in: inviteeEmails, mode: 'insensitive' }, inviteeEmail: { in: inviteeEmails },
}, },
}); });
return E.right(true); return E.right(true);
@@ -194,7 +189,6 @@ export class AdminService {
NOT: { NOT: {
inviteeEmail: { inviteeEmail: {
in: userEmailObjs.map((user) => user.email), in: userEmailObjs.map((user) => user.email),
mode: 'insensitive',
}, },
}, },
}, },

View File

@@ -299,10 +299,7 @@ export class ShortcodeService implements UserDataHandler, OnModuleInit {
where: userEmail where: userEmail
? { ? {
User: { User: {
email: { email: userEmail,
equals: userEmail,
mode: 'insensitive',
},
}, },
} }
: undefined, : undefined,

View File

@@ -75,13 +75,12 @@ export class TeamInvitationService {
if (!isEmailValid) return E.left(INVALID_EMAIL); if (!isEmailValid) return E.left(INVALID_EMAIL);
try { try {
const teamInvite = await this.prisma.teamInvitation.findFirstOrThrow({ const teamInvite = await this.prisma.teamInvitation.findUniqueOrThrow({
where: { where: {
inviteeEmail: { teamID_inviteeEmail: {
equals: inviteeEmail, inviteeEmail: inviteeEmail,
mode: 'insensitive', teamID: teamID,
}, },
teamID,
}, },
}); });

View File

@@ -149,7 +149,7 @@ beforeEach(() => {
describe('UserService', () => { describe('UserService', () => {
describe('findUserByEmail', () => { describe('findUserByEmail', () => {
test('should successfully return a valid user given a valid email', async () => { test('should successfully return a valid user given a valid email', async () => {
mockPrisma.user.findFirst.mockResolvedValueOnce(user); mockPrisma.user.findUniqueOrThrow.mockResolvedValueOnce(user);
const result = await userService.findUserByEmail( const result = await userService.findUserByEmail(
'dwight@dundermifflin.com', 'dwight@dundermifflin.com',
@@ -158,7 +158,7 @@ describe('UserService', () => {
}); });
test('should return a null user given a invalid email', async () => { test('should return a null user given a invalid email', async () => {
mockPrisma.user.findFirst.mockResolvedValueOnce(null); mockPrisma.user.findUniqueOrThrow.mockRejectedValueOnce('NotFoundError');
const result = await userService.findUserByEmail('jim@dundermifflin.com'); const result = await userService.findUserByEmail('jim@dundermifflin.com');
expect(result).resolves.toBeNone; expect(result).resolves.toBeNone;

View File

@@ -62,16 +62,16 @@ export class UserService {
* @returns Option of found User * @returns Option of found User
*/ */
async findUserByEmail(email: string): Promise<O.None | O.Some<AuthUser>> { async findUserByEmail(email: string): Promise<O.None | O.Some<AuthUser>> {
const user = await this.prisma.user.findFirst({ try {
where: { const user = await this.prisma.user.findUniqueOrThrow({
email: { where: {
equals: email, email: email,
mode: 'insensitive',
}, },
}, });
}); return O.some(user);
if (!user) return O.none; } catch (error) {
return O.some(user); return O.none;
}
} }
/** /**

View File

@@ -400,7 +400,7 @@ const HoppTestResultSchema = z
(x) => "secret" in x && !x.secret (x) => "secret" in x && !x.secret
).and( ).and(
z.object({ z.object({
previousValue: z.string(), previousValue: z.optional(z.string()),
}) })
) )
), ),
@@ -415,7 +415,7 @@ const HoppTestResultSchema = z
(x) => "secret" in x && !x.secret (x) => "secret" in x && !x.secret
).and( ).and(
z.object({ z.object({
previousValue: z.string(), previousValue: z.optional(z.string()),
}) })
) )
), ),