offer groups with status

This commit is contained in:
ntr committed 2022-10-29 12:42:01 +11:00
1 parent b199ce94c1
commit 15a84d6eea
6 files changed
+29 -44

No files matched your search

+1 -1
View File
@@ -28,7 +28,7 @@ async function start() {
events,
} = createServices(log);
events.emit(Events.StartupSync);
// events.emit(Events.StartupSync);
// events.emit(Events.ListingsUpdated);
api.listen();
+14 -1
View File
@@ -149,7 +149,20 @@ export default function createOffers(log: Log, pg: Pg) {
async function userOffers(user: User) {
const offers = await pg.userOffers(user);
return groupBy(offers, (o) => o.wantId);
const groups = Object.values(groupBy(offers, (o) => o.wantId))
.map(g => {
const offers = sortBy(g, sortOffers);
const status = offers[0].status;
const details = offers[0].want.data;
return {
details,
offers,
status,
};
});
return groups;
}
return {
+4 -28
View File
@@ -11,33 +11,7 @@ export interface UserCreateParams {
password: string,
}
export interface Pg {
userFindId: (id: UUID) => Promise<User>,
userFindEmail: (email: Email) => Promise<User>,
userCreate: (params: UserCreateParams) => Promise<User>,
userWants: (user: User) => Promise<Want[]>,
userOffers: (user: User) => Promise<Offer[]>,
userOfferFind: (user: User, id: UUID) => Promise<Offer>,
listingUpsert: (listing: Listing, want: Want) => Promise<Listing>,
listingFind: (id: DiscogsListing) => Promise<Listing>,
listingByIds: (ids: DiscogsListing[]) => Promise<Listing[]>,
listingRmUnlisted: (want: Want, ids: DiscogsListing[]) => Promise<number>,
wantCreate: (discogsWant: any, user: User) => Promise<Want>,
wantList: (user: User) => Promise<Want[]>,
wantsToSync: () => Promise<Want[]>,
wantRm: (id: UUID) => Promise<void>,
bundleCandidates: () => Promise<Listing[][]>,
offersCreate: (offers: Offer[]) => Promise<Offer[]>,
offerStatusSet: (id: UUID, status: Status) => Promise<Offer>,
offersAdmin: () => Promise<Offer[]>,
offerFindId: (id: UUID) => Promise<Offer>,
}
export default function createPg(log: Log, prisma: PrismaClient): Pg {
export default function createPg(log: Log, prisma: PrismaClient) {
async function userFindId(id: UUID) {
return prisma.user.findUnique({ where: { id }});
}
@@ -324,4 +298,6 @@ export default function createPg(log: Log, prisma: PrismaClient): Pg {
offersAdmin,
offerFindId,
};
}
}
export type Pg = ReturnType<typeof createPg>;