refactor packages
This commit is contained in:
37
packages/db/src/services/salt.service.ts
Normal file
37
packages/db/src/services/salt.service.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { db } from '../prisma-client';
|
||||
|
||||
export async function getCurrentSalt() {
|
||||
const salt = await db.salt.findFirst({
|
||||
orderBy: {
|
||||
createdAt: 'desc',
|
||||
},
|
||||
});
|
||||
|
||||
if (!salt) {
|
||||
throw new Error('No salt found');
|
||||
}
|
||||
|
||||
return salt.salt;
|
||||
}
|
||||
|
||||
export async function getSalts() {
|
||||
const [curr, prev] = await db.salt.findMany({
|
||||
orderBy: {
|
||||
createdAt: 'desc',
|
||||
},
|
||||
take: 2,
|
||||
});
|
||||
|
||||
if (!curr) {
|
||||
throw new Error('No salt found');
|
||||
}
|
||||
|
||||
if (!prev) {
|
||||
throw new Error('No previous salt found');
|
||||
}
|
||||
|
||||
return {
|
||||
current: curr.salt,
|
||||
previous: prev.salt,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user