polysignal_hackaton / backend /src /watchlist /watchlist.repository.js
blackmistcode's picture
Add files using upload-large-folder tool
26cbf65 verified
Raw
History Blame Contribute Delete
1.44 kB
/**
* Repositorio de acceso a datos para el modelo Watchlist.
*
* Responsabilidades:
* - create(data) β†’ inserta entrada en watchlist.
* - findByUser(userId) β†’ lista con datos del mercado asociado.
* - deleteByUserAndMarket(...) β†’ elimina entrada especifica.
* - findAllWithThreshold() β†’ entradas con alertThreshold definido (para alertas).
*
* Constraint:
* - @@unique([userId, marketId]) β†’ un usuario no puede duplicar un mercado.
*
* Todas las operaciones usan Prisma ORM.
*/
import { prisma } from '../utils/prisma.js';
export const watchlistRepository = {
create({ userId, marketId, alertThreshold }) {
return prisma.watchlist.create({ data: { userId, marketId, alertThreshold } });
},
findByUser(userId) {
return prisma.watchlist.findMany({
where: { userId },
include: {
market: { select: { id: true, question: true, yesPrice: true, noPrice: true, status: true } },
},
orderBy: { createdAt: 'desc' },
});
},
deleteByUserAndMarket(userId, marketId) {
return prisma.watchlist.deleteMany({ where: { userId, marketId } });
},
findAllWithThreshold() {
return prisma.watchlist.findMany({
where: { alertThreshold: { not: null } },
include: {
user: { select: { id: true, telegramChatId: true } },
market: { select: { id: true, question: true, yesPrice: true } },
},
});
},
};