Files
formbricks/packages/lib/services/teamDetails.ts
Subhodip Roy 60c96fe3f9 Build Display service and rebuild display endpoint in app directory (#432)
* created new create-display and updated display endpoints with zod, db service-layer, and next.js route handlers

* changed the api URL and changed few type definations

* new getTeamDetails service is created which will be further used by display and response endpoints

* changed the prisma call with getTeamDetails service

* created display services and zod validation schema

* removed envId from func parameter

* fix build error by adding a type annotation

* Moved the return inside try block

* Removed comments

* changed the update display service name to markDisplayResponded

* Update route.ts

* reference person type in display, check response code first then transform to json

* add createdAt & updatedAt to person when query display

* pnpm format

* small optimizations

---------

Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
2023-07-07 12:28:47 +02:00

51 lines
1.2 KiB
TypeScript

import { prisma } from "@formbricks/database";
import { Prisma } from "@prisma/client";
import { DatabaseError, ResourceNotFoundError } from "@formbricks/errors";
export const getTeamDetails = async (environmentId: string) => {
try {
const environment = await prisma.environment.findUnique({
where: {
id: environmentId,
},
select: {
product: {
select: {
team: {
select: {
id: true,
memberships: {
select: {
userId: true,
role: true,
},
},
},
},
},
},
},
});
if (!environment) {
throw new ResourceNotFoundError("Environment", environmentId);
}
const teamId: string = environment.product.team.id;
// find team owner
const teamOwnerId: string | undefined = environment.product.team.memberships.find(
(m) => m.role === "owner"
)?.userId;
return {
teamId: teamId,
teamOwnerId: teamOwnerId,
};
} catch (error) {
if (error instanceof Prisma.PrismaClientKnownRequestError) {
throw new DatabaseError("Database operation failed");
}
throw error;
}
};