wants wip"

This commit is contained in:
ntr committed 2022-08-16 10:09:36 +10:00
1 parent c99f6fd2b6
commit f5e75f4fe6
7 files changed
+33 -12

No files matched your search

+10 -2
View File
@@ -147,7 +147,7 @@ export default function createApi(log: Log, pg: Pg, discogs) {
ctx.response.body = listings;
});
router.post('/want', async function wantPost(ctx, next) {
router.get('/wants', async function wantPost(ctx, next) {
const { userId, releaseId } = ctx.request.body;
const user = await pg.userFindId(userId);
const release = await discogs.release(releaseId);
@@ -155,7 +155,15 @@ export default function createApi(log: Log, pg: Pg, discogs) {
ctx.response.body = want;
});
router.post('/want/search', async function wantPost(ctx, next) {
router.get('/wants', async function wantGet(ctx, next) {
ctx.assert(ctx.isAuthenticated(), 401, 'log in required');
log.warn(ctx.state.user);
const user = ctx.state.user;
const wants = await pg.wantFind(user);
ctx.response.body = wants;
});
router.post('/wants/search', async function wantPost(ctx, next) {
const { artist, title } = ctx.request.body;
const results = await discogs.search(artist, title);
ctx.response.body = results;
+7
View File
@@ -17,6 +17,7 @@ export interface Pg {
userWants: (user: User) => Promise<Want[]>,
wantUpsert: (want: Want, user: User) => Promise<Want>,
wantFind: (user: User) => Promise<Want[]>,
listingUpsert: (listing: Listing, want: Want) => Promise<Listing>,
listingFind: (id: DiscogsListing) => Promise<Listing>,
listingRmUnlisted: (want: Want, ids: DiscogsListing[]) => Promise<number>,
@@ -53,6 +54,12 @@ export default function createPg(log: Log, prisma: PrismaClient): Pg {
});
}
async function wantList(user: User) {
return prisma.want.findMany({
where: { userId: user.id },
});
}
async function wantUpsert(dcWant, user) {
const values: { userId: UUID, release: DiscogsListing, data: any } = {
data: dcWant,