Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/__tests__/find/find-order-by.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,21 @@ describe('find', () => {
warnings: null,
password: 'password5',
birthday: new Date(now - 1000000000200),
money: BigInt(2),
},
{
email: 'user4@company.com',
warnings: 15,
password: 'password4',
birthday: new Date(now - 1000000000000),
money: BigInt(1),
},
{
email: 'user6@company.com',
warnings: 15,
password: 'password3',
birthday: new Date(now - 1000000000100),
money: BigInt(3),
},
];

Expand Down Expand Up @@ -171,6 +174,20 @@ describe('find', () => {
}
});

it('Should return ordered items based on bitints', async () => {
const mockUsers = await prismock.user.findMany({
orderBy: { money: 'desc' },
select: { money: true, email: true },
});

const realUsers = await prisma.user.findMany({
orderBy: { money: 'desc' },
select: { money: true, email: true },
});

expect(mockUsers).toEqual(realUsers);
});

it('Should return ordered items based on string', async () => {
const mockUsers = await prismock.user.findMany({
orderBy: { email: 'desc' },
Expand Down
4 changes: 4 additions & 0 deletions src/lib/operations/find/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ export function calculateOrder(
weight = values[0] - values[1];
}

if (typeof values[0] === 'bigint' && typeof values[1] === 'bigint') {
weight = Number(values[0]) - Number(values[1]);
}

if (typeof values[0] === 'string' && typeof values[1] === 'string') {
weight = values[0].localeCompare(values[1]);
}
Expand Down