New schema for pixels and links.
This commit is contained in:
71
src/queries/prisma/link.ts
Normal file
71
src/queries/prisma/link.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { Prisma, Link } from '@prisma/client';
|
||||
import prisma from '@/lib/prisma';
|
||||
import { PageResult, QueryFilters } from '@/lib/types';
|
||||
|
||||
async function findLink(criteria: Prisma.LinkFindUniqueArgs): Promise<Link> {
|
||||
return prisma.client.link.findUnique(criteria);
|
||||
}
|
||||
|
||||
export async function getLink(linkId: string): Promise<Link> {
|
||||
return findLink({
|
||||
where: {
|
||||
id: linkId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function getLinks(
|
||||
criteria: Prisma.LinkFindManyArgs,
|
||||
filters: QueryFilters = {},
|
||||
): Promise<PageResult<Link[]>> {
|
||||
const { search } = filters;
|
||||
|
||||
const where: Prisma.LinkWhereInput = {
|
||||
...criteria.where,
|
||||
...prisma.getSearchParameters(search, [{ name: 'contains' }]),
|
||||
};
|
||||
|
||||
return prisma.pagedQuery('link', { ...criteria, where }, filters);
|
||||
}
|
||||
|
||||
export async function getUserLinks(
|
||||
userId: string,
|
||||
filters?: QueryFilters,
|
||||
): Promise<PageResult<Link[]>> {
|
||||
return getLinks(
|
||||
{
|
||||
where: {
|
||||
userId,
|
||||
deletedAt: null,
|
||||
},
|
||||
},
|
||||
filters,
|
||||
);
|
||||
}
|
||||
|
||||
export async function getTeamLinks(
|
||||
teamId: string,
|
||||
filters?: QueryFilters,
|
||||
): Promise<PageResult<Link[]>> {
|
||||
return getLinks(
|
||||
{
|
||||
where: {
|
||||
teamId,
|
||||
deletedAt: null,
|
||||
},
|
||||
},
|
||||
filters,
|
||||
);
|
||||
}
|
||||
|
||||
export async function createLink(data: Prisma.LinkUncheckedCreateInput): Promise<Link> {
|
||||
return prisma.client.link.create({ data });
|
||||
}
|
||||
|
||||
export async function updateLink(linkId: string, data: any): Promise<Link> {
|
||||
return prisma.client.link.update({ where: { id: linkId }, data });
|
||||
}
|
||||
|
||||
export async function deleteLink(linkId: string): Promise<Link> {
|
||||
return prisma.client.link.delete({ where: { id: linkId } });
|
||||
}
|
||||
Reference in New Issue
Block a user