prod nginx changes and remove want on offer complete

This commit is contained in:
ntr committed 2022-09-15 22:14:54 +10:00
1 parent 2c66c47163
commit 644398319d
6 files changed
+52 -18

No files matched your search

+12 -4
View File
@@ -5,7 +5,7 @@ import groupBy from 'lodash/groupBy';
import sortBy from 'lodash/sortBy';
import { Context } from 'koa';
import { logAxiosError } from './utils';
import { logAxiosError, wantDetails } from './utils';
import { Pg } from './pg';
export enum Status {
@@ -65,9 +65,17 @@ export default function createOffers(log: Log, pg: Pg) {
}
async function statusSet(user: User, id: UUID, status: Status) {
// check the user actually has this offer
const offer = await pg.userOfferFind(user, id);
return pg.offerStatusSet(offer.id, status);
log.info({ status, id }, 'setting offer status');
const offer = await pg.offerFindId(id);
const update = await pg.offerStatusSet(offer.id, status);
if (status === Status.Complete) {
log.info({ id, status }, 'completed offer, removing want...');
await pg.wantRm(offer.wantId);
}
return update;
}
async function bundles() {
+23
View File
@@ -27,12 +27,14 @@ export interface Pg {
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 {
@@ -60,6 +62,15 @@ export default function createPg(log: Log, prisma: PrismaClient): Pg {
});
}
async function offerFindId(id: UUID) {
return prisma.offer.findFirstOrThrow({
where: { id },
include: {
want: true,
}
});
}
async function userOfferFind(user: User, id: UUID) {
return prisma.offer.findFirstOrThrow({
where: {
@@ -86,6 +97,9 @@ export default function createPg(log: Log, prisma: PrismaClient): Pg {
});
}
// userUpdate({ email: 'jen@vdk.com', password: 'jen' });
// userUpdate({ email: 'james@mcd', password: 'james' });
async function userUpdate(params: UserCreateParams) {
const hashRounds = 10;
const password = await bcrypt.hash(params.password, hashRounds);
@@ -111,6 +125,12 @@ export default function createPg(log: Log, prisma: PrismaClient): Pg {
return prisma.want.findMany({});
}
async function wantRm(id: UUID) {
await prisma.want.delete({
where: { id },
});
}
async function wantCreate(discogsRelease, user) {
const data: { userId: UUID, release: DiscogsListing, data: any } = {
data: discogsRelease,
@@ -286,6 +306,8 @@ export default function createPg(log: Log, prisma: PrismaClient): Pg {
wantCreate,
wantList,
wantsToSync,
wantRm,
listingUpsert,
listingFind,
listingRmUnlisted,
@@ -296,5 +318,6 @@ export default function createPg(log: Log, prisma: PrismaClient): Pg {
offersCreate,
offerStatusSet,
offersAdmin,
offerFindId,
};
}
+3 -1
View File
@@ -23,4 +23,6 @@ export function wantDetails(want: Want) {
artist: data.artists_sort,
id: want.id
}
}
}
export function offerDetails() {}