mirror of
https://github.com/formbricks/formbricks.git
synced 2026-03-16 23:53:36 -05:00
Co-authored-by: Johannes <johannes@formbricks.com> Co-authored-by: Dhruwang Jariwala <dhruwang@Dhruwangs-MacBook-Pro.local> Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
92 lines
2.0 KiB
TypeScript
92 lines
2.0 KiB
TypeScript
import "server-only";
|
|
|
|
import { prisma } from "@formbricks/database";
|
|
|
|
import { DatabaseError } from "@formbricks/types/v1/errors";
|
|
import { TResponseNote } from "@formbricks/types/v1/responses";
|
|
import { Prisma } from "@prisma/client";
|
|
|
|
const select = {
|
|
id: true,
|
|
createdAt: true,
|
|
updatedAt: true,
|
|
text: true,
|
|
isEdited: true,
|
|
isResolved: true,
|
|
user: {
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
},
|
|
},
|
|
};
|
|
|
|
export const createResponseNote = async (
|
|
responseId: string,
|
|
userId: string,
|
|
text: string
|
|
): Promise<TResponseNote> => {
|
|
try {
|
|
const responseNote = await prisma.responseNote.create({
|
|
data: {
|
|
responseId: responseId,
|
|
userId: userId,
|
|
text: text,
|
|
},
|
|
select,
|
|
});
|
|
return responseNote;
|
|
} catch (error) {
|
|
if (error instanceof Prisma.PrismaClientKnownRequestError) {
|
|
throw new DatabaseError("Database operation failed");
|
|
}
|
|
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
export const updateResponseNote = async (responseNoteId: string, text: string): Promise<TResponseNote> => {
|
|
try {
|
|
const updatedResponseNote = await prisma.responseNote.update({
|
|
where: {
|
|
id: responseNoteId,
|
|
},
|
|
data: {
|
|
text: text,
|
|
updatedAt: new Date(),
|
|
isEdited: true,
|
|
},
|
|
select,
|
|
});
|
|
return updatedResponseNote;
|
|
} catch (error) {
|
|
if (error instanceof Prisma.PrismaClientKnownRequestError) {
|
|
throw new DatabaseError("Database operation failed");
|
|
}
|
|
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
export const resolveResponseNote = async (responseNoteId: string): Promise<TResponseNote> => {
|
|
try {
|
|
const responseNote = await prisma.responseNote.update({
|
|
where: {
|
|
id: responseNoteId,
|
|
},
|
|
data: {
|
|
updatedAt: new Date(),
|
|
isResolved: true,
|
|
},
|
|
select,
|
|
});
|
|
return responseNote;
|
|
} catch (error) {
|
|
if (error instanceof Prisma.PrismaClientKnownRequestError) {
|
|
throw new DatabaseError("Database operation failed");
|
|
}
|
|
|
|
throw error;
|
|
}
|
|
};
|