acp stuff
This commit is contained in:
1 parent
deb9eb3fc2
commit
047f606e83
14 files changed
+368
-44
No files matched your search
+45
-4
@@ -3,6 +3,8 @@ import type Log from 'bunyan';
|
||||
import type { PrismaClient, Want, User, Listing, Offer, Prisma } from '@prisma/client';
|
||||
import * as Bluebird from 'bluebird';
|
||||
|
||||
import { Status } from './offers';
|
||||
|
||||
export interface UserCreateParams {
|
||||
email: string,
|
||||
password: string,
|
||||
@@ -14,10 +16,11 @@ export interface Pg {
|
||||
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>,
|
||||
listingFindSeller: (id: DiscogsSeller) => Promise<Listing[]>,
|
||||
listingByIds: (ids: DiscogsListing[]) => Promise<Listing[]>,
|
||||
listingRmUnlisted: (want: Want, ids: DiscogsListing[]) => Promise<number>,
|
||||
|
||||
wantCreate: (discogsWant: any, user: User) => Promise<Want>,
|
||||
@@ -27,6 +30,8 @@ export interface Pg {
|
||||
bundleCandidates: () => Promise<Listing[][]>,
|
||||
|
||||
offersCreate: (offers: Offer[]) => Promise<Offer[]>,
|
||||
offerSetStatus: (id: UUID, status: Status) => Promise<Offer>,
|
||||
offersAdmin: () => Promise<Offer[]>,
|
||||
}
|
||||
|
||||
export default function createPg(log: Log, prisma: PrismaClient): Pg {
|
||||
@@ -45,6 +50,21 @@ export default function createPg(log: Log, prisma: PrismaClient): Pg {
|
||||
async function userOffers(user: User) {
|
||||
return prisma.offer.findMany({
|
||||
where: { userId: user.id },
|
||||
include: {
|
||||
want: true,
|
||||
},
|
||||
orderBy: {
|
||||
status: 'desc',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function userOfferFind(user: User, id: UUID) {
|
||||
return prisma.offer.findFirstOrThrow({
|
||||
where: {
|
||||
userId: user.id,
|
||||
id,
|
||||
},
|
||||
include: {
|
||||
want: true,
|
||||
}
|
||||
@@ -145,10 +165,10 @@ export default function createPg(log: Log, prisma: PrismaClient): Pg {
|
||||
});
|
||||
}
|
||||
|
||||
async function listingFindSeller(seller: DiscogsSeller): Promise<Listing[]> {
|
||||
async function listingByIds(ids: DiscogsListing[]) {
|
||||
return prisma.listing.findMany({
|
||||
where: {
|
||||
seller,
|
||||
id: { in: ids },
|
||||
},
|
||||
include: {
|
||||
want: {
|
||||
@@ -199,12 +219,30 @@ export default function createPg(log: Log, prisma: PrismaClient): Pg {
|
||||
);
|
||||
}
|
||||
|
||||
async function offerSetStatus(id: UUID, status: Status) {
|
||||
return prisma.offer.update({
|
||||
where: { id: id },
|
||||
data: { status },
|
||||
});
|
||||
}
|
||||
|
||||
async function offersAdmin() {
|
||||
return prisma.offer.findMany({
|
||||
include: {
|
||||
listing: true,
|
||||
user: true,
|
||||
want: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
userFindId,
|
||||
userFindEmail,
|
||||
userCreate,
|
||||
userWants,
|
||||
userOffers,
|
||||
userOfferFind,
|
||||
|
||||
wantCreate,
|
||||
wantList,
|
||||
@@ -212,9 +250,12 @@ export default function createPg(log: Log, prisma: PrismaClient): Pg {
|
||||
listingUpsert,
|
||||
listingFind,
|
||||
listingRmUnlisted,
|
||||
listingFindSeller,
|
||||
listingByIds,
|
||||
|
||||
bundleCandidates,
|
||||
|
||||
offersCreate,
|
||||
offerSetStatus,
|
||||
offersAdmin,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user