sendou.ink/app/models/TrustRelationship.server.ts
2022-01-21 09:29:52 +02:00

43 lines
890 B
TypeScript

import { Prisma } from ".prisma/client";
import { db } from "~/utils/db.server";
export type FindManyByTrustReceiverId = Prisma.PromiseReturnType<
typeof findManyByTrustReceiverId
>;
export function findManyByTrustReceiverId(userId: string) {
return db.trustRelationships.findMany({
where: { trustReceiverId: userId },
select: {
trustGiver: {
select: {
id: true,
discordName: true,
},
},
},
});
}
export type Upsert = Prisma.PromiseReturnType<typeof upsert>;
export function upsert({
trustGiverId,
trustReceiverId,
}: {
trustGiverId: string;
trustReceiverId: string;
}) {
return db.trustRelationships.upsert({
where: {
trustGiverId_trustReceiverId: {
trustGiverId,
trustReceiverId,
},
},
create: {
trustGiverId,
trustReceiverId,
},
update: {},
});
}