want events

This commit is contained in:
ntr committed 2022-08-17 23:22:48 +10:00
1 parent f5e75f4fe6
commit 30bf7426e4
19 files changed
+293 -108

No files matched your search

+10 -16
View File
@@ -16,8 +16,8 @@ export interface Pg {
userCreate: (params: UserCreateParams) => Promise<User>,
userWants: (user: User) => Promise<Want[]>,
wantUpsert: (want: Want, user: User) => Promise<Want>,
wantFind: (user: User) => Promise<Want[]>,
wantCreate: (discogsWant: any, user: User) => Promise<Want>,
wantList: (user: User) => Promise<Want[]>,
listingUpsert: (listing: Listing, want: Want) => Promise<Listing>,
listingFind: (id: DiscogsListing) => Promise<Listing>,
listingRmUnlisted: (want: Want, ids: DiscogsListing[]) => Promise<number>,
@@ -60,22 +60,15 @@ export default function createPg(log: Log, prisma: PrismaClient): Pg {
});
}
async function wantUpsert(dcWant, user) {
const values: { userId: UUID, release: DiscogsListing, data: any } = {
data: dcWant,
release: dcWant.id,
async function wantCreate(discogsRelease, user) {
const data: { userId: UUID, release: DiscogsListing, data: any } = {
data: discogsRelease,
release: discogsRelease.id,
userId: user.id,
};
return prisma.want.upsert({
// get these from the generated types
// ./node_modules/.prisma/client/index.d.ts
where: { userId_release: {
userId: values.userId,
release: values.release || null,
}},
update: values,
create: values,
return prisma.want.create({
data,
});
}
@@ -154,7 +147,8 @@ export default function createPg(log: Log, prisma: PrismaClient): Pg {
userCreate,
userWants,
wantUpsert,
wantCreate,
wantList,
listingUpsert,
listingFind,
listingRmUnlisted,