mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-06 09:00:18 -06:00
chore: move all services into the new folder structure (#948)
* chore: move environment services * chore: move all services
This commit is contained in:
67
packages/lib/responseNote/service.ts
Normal file
67
packages/lib/responseNote/service.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
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 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;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user