Add website annotations with chart markers and CRUD management
This commit is contained in:
1 parent
eea124bbf8
commit
64e4cc1c3b
24 files changed
+957
-3
No files matched your search
@@ -0,0 +1,64 @@
|
||||
import type { Prisma } from '@/generated/prisma/client';
|
||||
import prisma from '@/lib/prisma';
|
||||
import type { QueryFilters } from '@/lib/types';
|
||||
|
||||
export async function getAnnotation(annotationId: string) {
|
||||
return prisma.client.annotation.findUnique({
|
||||
where: {
|
||||
id: annotationId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function getWebsiteAnnotation(websiteId: string, annotationId: string) {
|
||||
return prisma.client.annotation.findFirst({
|
||||
where: { id: annotationId, websiteId },
|
||||
});
|
||||
}
|
||||
|
||||
export async function getWebsiteAnnotations(
|
||||
websiteId: string,
|
||||
filters: QueryFilters & { startDate?: Date; endDate?: Date } = {},
|
||||
) {
|
||||
const { search, startDate, endDate } = filters;
|
||||
const { getSearchParameters, pagedQuery } = prisma;
|
||||
|
||||
const where: Prisma.AnnotationWhereInput = {
|
||||
websiteId,
|
||||
...(startDate &&
|
||||
endDate && {
|
||||
date: {
|
||||
gte: startDate,
|
||||
lte: endDate,
|
||||
},
|
||||
}),
|
||||
...getSearchParameters(search, [
|
||||
{
|
||||
note: 'contains',
|
||||
},
|
||||
]),
|
||||
};
|
||||
|
||||
return pagedQuery(
|
||||
'annotation',
|
||||
{
|
||||
where,
|
||||
orderBy: {
|
||||
date: 'desc',
|
||||
},
|
||||
},
|
||||
filters,
|
||||
);
|
||||
}
|
||||
|
||||
export async function createAnnotation(data: Prisma.AnnotationUncheckedCreateInput) {
|
||||
return prisma.client.annotation.create({ data });
|
||||
}
|
||||
|
||||
export async function updateAnnotation(annotationId: string, data: Prisma.AnnotationUpdateInput) {
|
||||
return prisma.client.annotation.update({ where: { id: annotationId }, data });
|
||||
}
|
||||
|
||||
export async function deleteAnnotation(annotationId: string) {
|
||||
return prisma.client.annotation.delete({ where: { id: annotationId } });
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from './annotation';
|
||||
export * from './board';
|
||||
export * from './link';
|
||||
export * from './pixel';
|
||||
|
||||
@@ -83,6 +83,11 @@ function createDeleteTx(calls: string[]) {
|
||||
calls.push('segment');
|
||||
}),
|
||||
},
|
||||
annotation: {
|
||||
deleteMany: vi.fn(async () => {
|
||||
calls.push('annotation');
|
||||
}),
|
||||
},
|
||||
share: {
|
||||
deleteMany: vi.fn(async () => {
|
||||
calls.push('share');
|
||||
@@ -149,6 +154,7 @@ describe('website delete dependencies', () => {
|
||||
'session',
|
||||
'report',
|
||||
'segment',
|
||||
'annotation',
|
||||
'share',
|
||||
'websiteDelete',
|
||||
]);
|
||||
|
||||
@@ -237,6 +237,10 @@ export async function deleteWebsite(websiteId: string) {
|
||||
where: { websiteId },
|
||||
});
|
||||
|
||||
await tx.annotation.deleteMany({
|
||||
where: { websiteId },
|
||||
});
|
||||
|
||||
await tx.share.deleteMany({
|
||||
where: { entityId: websiteId },
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user