Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

refactor: use part group for services instead of service group

Brad Barbin61eabd33b00f
diff --git a/apps/carbon/app/modules/parts/parts.models.ts b/apps/carbon/app/modules/parts/parts.models.ts
index 2ce559b017..282589233a 100644
--- a/apps/carbon/app/modules/parts/parts.models.ts
+++ b/apps/carbon/app/modules/parts/parts.models.ts
@@ -165,6 +165,7 @@ export const serviceValidator = withZod(
id: zfd.text(z.string().optional()),
name: z.string().min(1, { message: "Name is required" }).max(255),
description: z.string().optional(),
+ partGroupId: zfd.text(z.string().optional()),
serviceType: z.enum(serviceType, {
errorMap: (issue, ctx) => ({
message: "Service type is required",
diff --git a/apps/carbon/app/modules/parts/parts.service.ts b/apps/carbon/app/modules/parts/parts.service.ts
index 1c145fbba4..8b7603ae8a 100644
--- a/apps/carbon/app/modules/parts/parts.service.ts
+++ b/apps/carbon/app/modules/parts/parts.service.ts
@@ -250,7 +250,7 @@ export async function getServices(
}
if (args.group) {
- query = query.eq("serviceGroupId", args.group);
+ query = query.eq("partGroupId", args.group);
}
if (args.supplierId) {
@@ -282,44 +282,6 @@ export async function getServicesList(
return query;
}
-export async function getServiceGroups(
- client: SupabaseClient<Database>,
- args?: GenericQueryFilters & { name: string | null }
-) {
- let query = client.from("serviceGroup").select("*", {
- count: "exact",
- });
-
- if (args?.name) {
- query = query.ilike("name", `%${args.name}%`);
- }
-
- if (args) {
- query = setGenericQueryFilters(query, args, "name");
- }
-
- return query;
-}
-
-export async function getServiceGroupsList(
- client: SupabaseClient<Database>,
- args?: GenericQueryFilters & { name: string | null }
-) {
- let query = client
- .from("serviceGroup")
- .select("id, name", { count: "exact" });
-
- if (args?.name) {
- query = query.ilike("name", `%${args.name}%`);
- }
-
- if (args) {
- query = setGenericQueryFilters(query, args, "name");
- }
-
- return query;
-}
-
export async function getServiceSuppliers(
client: SupabaseClient<Database>,
id: string
diff --git a/apps/carbon/app/modules/parts/ui/Service/ServiceForm/ServiceForm.tsx b/apps/carbon/app/modules/parts/ui/Service/ServiceForm/ServiceForm.tsx
index 36dfd0aec3..a0ef41ea3e 100644
--- a/apps/carbon/app/modules/parts/ui/Service/ServiceForm/ServiceForm.tsx
+++ b/apps/carbon/app/modules/parts/ui/Service/ServiceForm/ServiceForm.tsx
@@ -29,16 +29,16 @@ type ServiceFormProps = {
const ServiceForm = ({ initialValues }: ServiceFormProps) => {
const sharedData = useRouteData<{
- serviceGroups: ListItem[];
+ partGroups: ListItem[];
}>(path.to.serviceRoot);
const permissions = usePermissions();
const isEditing = initialValues.id !== undefined;
- const serviceGroupOptions =
- sharedData?.serviceGroups.map((serviceGroup) => ({
- label: serviceGroup.name,
- value: serviceGroup.id,
+ const partGroupOptions =
+ sharedData?.partGroups.map((partGroup) => ({
+ label: partGroup.name,
+ value: partGroup.id,
})) ?? [];
const serviceTypeOptions =
@@ -85,9 +85,9 @@ const ServiceForm = ({ initialValues }: ServiceFormProps) => {
options={serviceTypeOptions}
/>
<Select
- name="serviceGroupId"
- label="Service Group"
- options={serviceGroupOptions}
+ name="partGroupId"
+ label="Part Group"
+ options={partGroupOptions}
/>
</VStack>
<VStack alignItems="start" spacing={2} w="full">
diff --git a/apps/carbon/app/modules/parts/ui/Service/ServicePreview/ServicePreview.tsx b/apps/carbon/app/modules/parts/ui/Service/ServicePreview/ServicePreview.tsx
index b645f8c682..2946f2ba62 100644
--- a/apps/carbon/app/modules/parts/ui/Service/ServicePreview/ServicePreview.tsx
+++ b/apps/carbon/app/modules/parts/ui/Service/ServicePreview/ServicePreview.tsx
@@ -52,8 +52,8 @@ const ServicePreview = () => {
alignItems="start"
justifyContent="space-between"
>
- <Text color="gray.500">Service Group</Text>
- <Text fontWeight="bold">{routeData?.service?.serviceGroup}</Text>
+ <Text color="gray.500">Part Group</Text>
+ <Text fontWeight="bold">{routeData?.service?.partGroup}</Text>
</Stack>
</Stack>
</CardBody>
diff --git a/apps/carbon/app/modules/parts/ui/Services/ServicesTable/ServicesTable.tsx b/apps/carbon/app/modules/parts/ui/Services/ServicesTable/ServicesTable.tsx
index 86f6cadc5b..97e5e75341 100644
--- a/apps/carbon/app/modules/parts/ui/Services/ServicesTable/ServicesTable.tsx
+++ b/apps/carbon/app/modules/parts/ui/Services/ServicesTable/ServicesTable.tsx
@@ -40,8 +40,8 @@ const ServicesTable = memo(({ data, count }: ServicesTableProps) => {
},
{
// @ts-ignore
- accessorKey: "serviceGroup",
- header: "Service Group",
+ accessorKey: "partGroup",
+ header: "Part Group",
cell: (item) => item.getValue(),
},
];
diff --git a/apps/carbon/app/modules/parts/ui/Services/ServicesTableFilters/ServicesTableFilters.tsx b/apps/carbon/app/modules/parts/ui/Services/ServicesTableFilters/ServicesTableFilters.tsx
index f05c018303..5f2bcd2690 100644
--- a/apps/carbon/app/modules/parts/ui/Services/ServicesTableFilters/ServicesTableFilters.tsx
+++ b/apps/carbon/app/modules/parts/ui/Services/ServicesTableFilters/ServicesTableFilters.tsx
@@ -9,10 +9,10 @@ import type { ListItem } from "~/types";
import { path } from "~/utils/path";
type ServicesTableFiltersProps = {
- serviceGroups: ListItem[];
+ partGroups: ListItem[];
};
-const ServicesTableFilters = ({ serviceGroups }: ServicesTableFiltersProps) => {
+const ServicesTableFilters = ({ partGroups }: ServicesTableFiltersProps) => {
const [params, setParams] = useUrlParams();
const permissions = usePermissions();
const serviceTypeOptions = serviceType.map((type) => ({
@@ -20,7 +20,7 @@ const ServicesTableFilters = ({ serviceGroups }: ServicesTableFiltersProps) => {
label: type,
}));
- const serviceGroupsOptions = serviceGroups.map((group) => ({
+ const partGroupsOptions = partGroups.map((group) => ({
value: group.id,
label: group.name,
}));
@@ -44,14 +44,14 @@ const ServicesTableFilters = ({ serviceGroups }: ServicesTableFiltersProps) => {
minW={180}
placeholder="Search Services"
/>
- {serviceGroupsOptions.length > 0 && (
+ {partGroupsOptions.length > 0 && (
<Select
size="sm"
isClearable
- value={serviceGroupsOptions.find(
+ value={partGroupsOptions.find(
(type) => type.value === params.get("group")
)}
- options={serviceGroupsOptions}
+ options={partGroupsOptions}
onChange={(selected) => {
setParams({ group: selected?.value });
}}
diff --git a/apps/carbon/app/modules/parts/ui/usePartsSidebar.tsx b/apps/carbon/app/modules/parts/ui/usePartsSidebar.tsx
index 6087585174..4dfd326fc1 100644
--- a/apps/carbon/app/modules/parts/ui/usePartsSidebar.tsx
+++ b/apps/carbon/app/modules/parts/ui/usePartsSidebar.tsx
@@ -29,11 +29,6 @@ const partsRoutes: AuthenticatedRouteGroup[] = [
to: path.to.partGroups,
role: "employee",
},
- // {
- // name: "Service Groups",
- // to: path.to.serviceGroups,
- // role: "employee",
- // },
{
name: "Units of Measure",
to: path.to.uoms,
diff --git a/apps/carbon/app/routes/x+/parts+/services.tsx b/apps/carbon/app/routes/x+/parts+/services.tsx
index a9c1e4b489..9c672f0148 100644
--- a/apps/carbon/app/routes/x+/parts+/services.tsx
+++ b/apps/carbon/app/routes/x+/parts+/services.tsx
@@ -5,7 +5,7 @@ import { Outlet, useLoaderData } from "@remix-run/react";
import {
ServicesTable,
ServicesTableFilters,
- getServiceGroupsList,
+ getPartGroupsList,
getServices,
} from "~/modules/parts";
import { requirePermissions } from "~/services/auth";
@@ -35,7 +35,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
const { limit, offset, sorts, filters } =
getGenericQueryFilters(searchParams);
- const [services, serviceGroups] = await Promise.all([
+ const [services, partGroups] = await Promise.all([
getServices(client, {
search,
type,
@@ -46,7 +46,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
sorts,
filters,
}),
- getServiceGroupsList(client),
+ getPartGroupsList(client),
]);
if (services.error) {
@@ -59,16 +59,16 @@ export async function loader({ request }: LoaderFunctionArgs) {
return json({
count: services.count ?? 0,
services: services.data ?? [],
- serviceGroups: serviceGroups.data ?? [],
+ partGroups: partGroups.data ?? [],
});
}
export default function ServicesSearchRoute() {
- const { count, services, serviceGroups } = useLoaderData<typeof loader>();
+ const { count, services, partGroups } = useLoaderData<typeof loader>();
return (
<VStack w="full" h="full" spacing={0}>
- <ServicesTableFilters serviceGroups={serviceGroups} />
+ <ServicesTableFilters partGroups={partGroups} />
<ServicesTable data={services} count={count} />
<Outlet />
</VStack>
diff --git a/apps/carbon/app/routes/x+/service+/$serviceId.index.tsx b/apps/carbon/app/routes/x+/service+/$serviceId.index.tsx
index 79aa1055fe..eaf3968b8c 100644
--- a/apps/carbon/app/routes/x+/service+/$serviceId.index.tsx
+++ b/apps/carbon/app/routes/x+/service+/$serviceId.index.tsx
@@ -59,7 +59,7 @@ export default function ServiceDetailsRoute() {
name: routeData.service?.name ?? "",
description: routeData.service?.description ?? undefined,
serviceType: routeData.service?.serviceType ?? "Internal",
- serviceGroupId: routeData.service?.serviceGroupId ?? undefined,
+ partGroupId: routeData.service?.partGroupId ?? undefined,
active: routeData.service?.active ?? true,
blocked: routeData.service?.blocked ?? false,
};
diff --git a/apps/carbon/app/routes/x+/service+/_layout.tsx b/apps/carbon/app/routes/x+/service+/_layout.tsx
index 7e28700b2f..d4243562d5 100644
--- a/apps/carbon/app/routes/x+/service+/_layout.tsx
+++ b/apps/carbon/app/routes/x+/service+/_layout.tsx
@@ -1,7 +1,7 @@
import { VStack } from "@chakra-ui/react";
import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
import { Outlet } from "@remix-run/react";
-import { getServiceGroupsList } from "~/modules/parts";
+import { getPartGroupsList } from "~/modules/parts";
import { getLocationsList } from "~/modules/resources";
import { requirePermissions } from "~/services/auth";
import type { Handle } from "~/utils/handle";
@@ -22,14 +22,14 @@ export async function loader({ request }: LoaderFunctionArgs) {
view: "parts",
});
- const [serviceGroups, locations] = await Promise.all([
- getServiceGroupsList(client),
+ const [partGroups, locations] = await Promise.all([
+ getPartGroupsList(client),
getLocationsList(client),
]);
return {
locations: locations?.data ?? [],
- serviceGroups: serviceGroups?.data ?? [],
+ partGroups: partGroups?.data ?? [],
};
}
diff --git a/packages/database/SCHEMA.md b/packages/database/SCHEMA.md
index e977a867b7..b4c64c5c45 100644
--- a/packages/database/SCHEMA.md
+++ b/packages/database/SCHEMA.md
@@ -1,6 +1,4 @@
-# Carbon Database Schema
-
-This file is generated by `scripts/generate-schema-md.ts` using the migrations in `packages/database/supabase/migrations`.
+# Carbon Database Schema by `scripts/generate-schema-md.ts` using the migrations in `packages/database/supabase/migrations`.
@@ -7008,53 +7006,6 @@ CREATE TRIGGER create_customer_entries
## `services`
```sql
-CREATE TABLE "serviceGroup" (
- "id" TEXT NOT NULL DEFAULT xid(),
- "name" TEXT NOT NULL,
- "description" TEXT,
- "active" BOOLEAN NOT NULL DEFAULT true,
- "createdBy" TEXT NOT NULL,
- "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
- "updatedBy" TEXT,
- "updatedAt" TIMESTAMP WITH TIME ZONE,
-
- CONSTRAINT "serviceGroup_pkey" PRIMARY KEY ("id"),
- CONSTRAINT "serviceGroup_name_key" UNIQUE ("name"),
- CONSTRAINT "serviceGroup_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id"),
- CONSTRAINT "serviceGroup_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user"("id")
-);
-
-ALTER TABLE "serviceGroup" ENABLE ROW LEVEL SECURITY;
-
-CREATE POLICY "Employees with parts_view can view service groups" ON "serviceGroup"
- FOR SELECT
- USING (
- coalesce(get_my_claim('parts_view')::boolean, false) = true
- AND (get_my_claim('role'::text)) = '"employee"'::jsonb
- );
-
-
-CREATE POLICY "Employees with parts_create can insert service groups" ON "serviceGroup"
- FOR INSERT
- WITH CHECK (
- coalesce(get_my_claim('parts_create')::boolean,false)
- AND (get_my_claim('role'::text)) = '"employee"'::jsonb
-);
-
-CREATE POLICY "Employees with parts_update can update service groups" ON "serviceGroup"
- FOR UPDATE
- USING (
- coalesce(get_my_claim('parts_update')::boolean, false) = true
- AND (get_my_claim('role'::text)) = '"employee"'::jsonb
- );
-
-CREATE POLICY "Employees with parts_delete can delete service groups" ON "serviceGroup"
- FOR DELETE
- USING (
- coalesce(get_my_claim('parts_delete')::boolean, false) = true
- AND (get_my_claim('role'::text)) = '"employee"'::jsonb
- );
-
CREATE TYPE "serviceType" AS ENUM (
'Internal',
'External'
@@ -7065,7 +7016,7 @@ CREATE TABLE "service" (
"name" TEXT NOT NULL,
"description" TEXT,
"blocked" BOOLEAN NOT NULL DEFAULT false,
- "serviceGroupId" TEXT,
+ "partGroupId" TEXT,
"serviceType" "serviceType" NOT NULL,
"active" BOOLEAN NOT NULL DEFAULT true,
"approved" BOOLEAN NOT NULL DEFAULT false,
@@ -7078,7 +7029,7 @@ CREATE TABLE "service" (
"updatedAt" TIMESTAMP WITH TIME ZONE,
CONSTRAINT "service_pkey" PRIMARY KEY ("id"),
- CONSTRAINT "service_serviceGroupId_fkey" FOREIGN KEY ("serviceGroupId") REFERENCES "serviceGroup"("id"),
+ CONSTRAINT "service_partGroupId_fkey" FOREIGN KEY ("partGroupId") REFERENCES "partGroup"("id"),
CONSTRAINT "service_approvedBy_fkey" FOREIGN KEY ("approvedBy") REFERENCES "user"("id"),
CONSTRAINT "service_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id"),
CONSTRAINT "service_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user"("id")
@@ -7189,20 +7140,20 @@ CREATE OR REPLACE VIEW "services" WITH(SECURITY_INVOKER=true) AS
s.name,
s.description,
s."serviceType",
- sg.id AS "serviceGroupId",
- sg.name AS "serviceGroup",
+ pg.id AS "partGroupId",
+ pg.name AS "partGroup",
s.active,
s.blocked,
array_agg(ss."supplierId") AS "supplierIds"
FROM "service" s
- LEFT JOIN "serviceGroup" sg ON sg.id = s."serviceGroupId"
+ LEFT JOIN "partGroup" pg ON pg.id = s."partGroupId"
LEFT JOIN "serviceSupplier" ss ON ss."serviceId" = s.id
GROUP BY s.id,
s.name,
s.description,
s."serviceType",
- sg.id,
- sg.name,
+ pg.id,
+ pg.name,
s.active;
```
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 8c866c4255..bf98046750 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -3167,6 +3167,12 @@ export interface Database {
referencedRelation: "partGroup";
referencedColumns: ["id"];
},
+ {
+ foreignKeyName: "part_partGroupId_fkey";
+ columns: ["partGroupId"];
+ referencedRelation: "services";
+ referencedColumns: ["partGroupId"];
+ },
{
foreignKeyName: "part_unitOfMeasureCode_fkey";
columns: ["unitOfMeasureCode"];
@@ -4403,6 +4409,12 @@ export interface Database {
referencedRelation: "partGroup";
referencedColumns: ["id"];
},
+ {
+ foreignKeyName: "postingGroupInventory_partGroupId_fkey";
+ columns: ["partGroupId"];
+ referencedRelation: "services";
+ referencedColumns: ["partGroupId"];
+ },
{
foreignKeyName: "postingGroupInventory_purchaseVarianceAccount_fkey";
columns: ["purchaseVarianceAccount"];
@@ -4485,6 +4497,12 @@ export interface Database {
referencedRelation: "partGroup";
referencedColumns: ["id"];
},
+ {
+ foreignKeyName: "postingGroupPurchasing_partGroupId_fkey";
+ columns: ["partGroupId"];
+ referencedRelation: "services";
+ referencedColumns: ["partGroupId"];
+ },
{
foreignKeyName: "postingGroupPurchasing_payablesAccount_fkey";
columns: ["payablesAccount"];
@@ -4627,6 +4645,12 @@ export interface Database {
referencedRelation: "partGroup";
referencedColumns: ["id"];
},
+ {
+ foreignKeyName: "postingGroupSales_partGroupId_fkey";
+ columns: ["partGroupId"];
+ referencedRelation: "services";
+ referencedColumns: ["partGroupId"];
+ },
{
foreignKeyName: "postingGroupSales_receivablesAccount_fkey";
columns: ["receivablesAccount"];
@@ -6346,7 +6370,7 @@ export interface Database {
fromDate: string | null;
id: string;
name: string;
- serviceGroupId: string | null;
+ partGroupId: string | null;
serviceType: Database["public"]["Enums"]["serviceType"];
toDate: string | null;
updatedAt: string | null;
@@ -6363,7 +6387,7 @@ export interface Database {
fromDate?: string | null;
id?: string;
name: string;
- serviceGroupId?: string | null;
+ partGroupId?: string | null;
serviceType: Database["public"]["Enums"]["serviceType"];
toDate?: string | null;
updatedAt?: string | null;
@@ -6380,7 +6404,7 @@ export interface Database {
fromDate?: string | null;
id?: string;
name?: string;
- serviceGroupId?: string | null;
+ partGroupId?: string | null;
serviceType?: Database["public"]["Enums"]["serviceType"];
toDate?: string | null;
updatedAt?: string | null;
@@ -6412,16 +6436,16 @@ export interface Database {
referencedColumns: ["userId"];
},
{
- foreignKeyName: "service_serviceGroupId_fkey";
- columns: ["serviceGroupId"];
- referencedRelation: "serviceGroup";
+ foreignKeyName: "service_partGroupId_fkey";
+ columns: ["partGroupId"];
+ referencedRelation: "partGroup";
referencedColumns: ["id"];
},
{
- foreignKeyName: "service_serviceGroupId_fkey";
- columns: ["serviceGroupId"];
+ foreignKeyName: "service_partGroupId_fkey";
+ columns: ["partGroupId"];
referencedRelation: "services";
- referencedColumns: ["serviceGroupId"];
+ referencedColumns: ["partGroupId"];
},
{
foreignKeyName: "service_updatedBy_fkey";
@@ -6437,64 +6461,6 @@ export interface Database {
}
];
};
- serviceGroup: {
- Row: {
- active: boolean;
- createdAt: string;
- createdBy: string;
- description: string | null;
- id: string;
- name: string;
- updatedAt: string | null;
- updatedBy: string | null;
- };
- Insert: {
- active?: boolean;
- createdAt?: string;
- createdBy: string;
- description?: string | null;
- id?: string;
- name: string;
- updatedAt?: string | null;
- updatedBy?: string | null;
- };
- Update: {
- active?: boolean;
- createdAt?: string;
- createdBy?: string;
- description?: string | null;
- id?: string;
- name?: string;
- updatedAt?: string | null;
- updatedBy?: string | null;
- };
- Relationships: [
- {
- foreignKeyName: "serviceGroup_createdBy_fkey";
- columns: ["createdBy"];
- referencedRelation: "user";
- referencedColumns: ["id"];
- },
- {
- foreignKeyName: "serviceGroup_createdBy_fkey";
- columns: ["createdBy"];
- referencedRelation: "userDefaults";
- referencedColumns: ["userId"];
- },
- {
- foreignKeyName: "serviceGroup_updatedBy_fkey";
- columns: ["updatedBy"];
- referencedRelation: "user";
- referencedColumns: ["id"];
- },
- {
- foreignKeyName: "serviceGroup_updatedBy_fkey";
- columns: ["updatedBy"];
- referencedRelation: "userDefaults";
- referencedColumns: ["userId"];
- }
- ];
- };
serviceSupplier: {
Row: {
active: boolean;
@@ -8560,6 +8526,12 @@ export interface Database {
columns: ["partGroupId"];
referencedRelation: "partGroup";
referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "part_partGroupId_fkey";
+ columns: ["partGroupId"];
+ referencedRelation: "services";
+ referencedColumns: ["partGroupId"];
}
];
};
@@ -8876,8 +8848,8 @@ export interface Database {
description: string | null;
id: string | null;
name: string | null;
- serviceGroup: string | null;
- serviceGroupId: string | null;
+ partGroup: string | null;
+ partGroupId: string | null;
serviceType: Database["public"]["Enums"]["serviceType"] | null;
supplierIds: string[] | null;
};
diff --git a/packages/database/supabase/migrations/20231212120726_services.sql b/packages/database/supabase/migrations/20231212120726_services.sql
index a350bc3bdf..aa1ade624e 100644
--- a/packages/database/supabase/migrations/20231212120726_services.sql
+++ b/packages/database/supabase/migrations/20231212120726_services.sql
@@ -1,50 +1,3 @@
-CREATE TABLE "serviceGroup" (
- "id" TEXT NOT NULL DEFAULT xid(),
- "name" TEXT NOT NULL,
- "description" TEXT,
- "active" BOOLEAN NOT NULL DEFAULT true,
- "createdBy" TEXT NOT NULL,
- "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
- "updatedBy" TEXT,
- "updatedAt" TIMESTAMP WITH TIME ZONE,
-
- CONSTRAINT "serviceGroup_pkey" PRIMARY KEY ("id"),
- CONSTRAINT "serviceGroup_name_key" UNIQUE ("name"),
- CONSTRAINT "serviceGroup_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id"),
- CONSTRAINT "serviceGroup_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user"("id")
-);
-
-ALTER TABLE "serviceGroup" ENABLE ROW LEVEL SECURITY;
-
-CREATE POLICY "Employees with parts_view can view service groups" ON "serviceGroup"
- FOR SELECT
- USING (
- coalesce(get_my_claim('parts_view')::boolean, false) = true
- AND (get_my_claim('role'::text)) = '"employee"'::jsonb
- );
-
-
-CREATE POLICY "Employees with parts_create can insert service groups" ON "serviceGroup"
- FOR INSERT
- WITH CHECK (
- coalesce(get_my_claim('parts_create')::boolean,false)
- AND (get_my_claim('role'::text)) = '"employee"'::jsonb
-);
-
-CREATE POLICY "Employees with parts_update can update service groups" ON "serviceGroup"
- FOR UPDATE
- USING (
- coalesce(get_my_claim('parts_update')::boolean, false) = true
- AND (get_my_claim('role'::text)) = '"employee"'::jsonb
- );
-
-CREATE POLICY "Employees with parts_delete can delete service groups" ON "serviceGroup"
- FOR DELETE
- USING (
- coalesce(get_my_claim('parts_delete')::boolean, false) = true
- AND (get_my_claim('role'::text)) = '"employee"'::jsonb
- );
-
CREATE TYPE "serviceType" AS ENUM (
'Internal',
'External'
@@ -55,7 +8,7 @@ CREATE TABLE "service" (
"name" TEXT NOT NULL,
"description" TEXT,
"blocked" BOOLEAN NOT NULL DEFAULT false,
- "serviceGroupId" TEXT,
+ "partGroupId" TEXT,
"serviceType" "serviceType" NOT NULL,
"active" BOOLEAN NOT NULL DEFAULT true,
"approved" BOOLEAN NOT NULL DEFAULT false,
@@ -68,7 +21,7 @@ CREATE TABLE "service" (
"updatedAt" TIMESTAMP WITH TIME ZONE,
CONSTRAINT "service_pkey" PRIMARY KEY ("id"),
- CONSTRAINT "service_serviceGroupId_fkey" FOREIGN KEY ("serviceGroupId") REFERENCES "serviceGroup"("id"),
+ CONSTRAINT "service_partGroupId_fkey" FOREIGN KEY ("partGroupId") REFERENCES "partGroup"("id"),
CONSTRAINT "service_approvedBy_fkey" FOREIGN KEY ("approvedBy") REFERENCES "user"("id"),
CONSTRAINT "service_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id"),
CONSTRAINT "service_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user"("id")
@@ -179,18 +132,18 @@ CREATE OR REPLACE VIEW "services" WITH(SECURITY_INVOKER=true) AS
s.name,
s.description,
s."serviceType",
- sg.id AS "serviceGroupId",
- sg.name AS "serviceGroup",
+ pg.id AS "partGroupId",
+ pg.name AS "partGroup",
s.active,
s.blocked,
array_agg(ss."supplierId") AS "supplierIds"
FROM "service" s
- LEFT JOIN "serviceGroup" sg ON sg.id = s."serviceGroupId"
+ LEFT JOIN "partGroup" pg ON pg.id = s."partGroupId"
LEFT JOIN "serviceSupplier" ss ON ss."serviceId" = s.id
GROUP BY s.id,
s.name,
s.description,
s."serviceType",
- sg.id,
- sg.name,
+ pg.id,
+ pg.name,
s.active;
\ No newline at end of file