Compare commits

..

1 Commits

Author SHA1 Message Date
nivedin
0b842fe197 fix: precision lost when json is beautified 2024-05-23 22:26:14 +05:30
7 changed files with 23 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

@@ -89,6 +89,7 @@ import { readFileAsText } from "~/helpers/functional/files"
import xmlFormat from "xml-formatter" import xmlFormat from "xml-formatter"
import { useNestedSetting } from "~/composables/settings" import { useNestedSetting } from "~/composables/settings"
import { toggleNestedSetting } from "~/newstore/settings" import { toggleNestedSetting } from "~/newstore/settings"
import * as LJSON from "lossless-json"
type PossibleContentTypes = Exclude< type PossibleContentTypes = Exclude<
ValidContentTypes, ValidContentTypes,
@@ -187,8 +188,8 @@ const prettifyRequestBody = () => {
let prettifyBody = "" let prettifyBody = ""
try { try {
if (body.value.contentType.endsWith("json")) { if (body.value.contentType.endsWith("json")) {
const jsonObj = JSON.parse(rawParamsBody.value as string) const jsonObj = LJSON.parse(rawParamsBody.value as string)
prettifyBody = JSON.stringify(jsonObj, null, 2) prettifyBody = LJSON.stringify(jsonObj, undefined, 2) as string
} else if (body.value.contentType === "application/xml") { } else if (body.value.contentType === "application/xml") {
prettifyBody = prettifyXML(rawParamsBody.value as string) prettifyBody = prettifyXML(rawParamsBody.value as string)
} }