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.

feat: add and update service with item abstraction

Brad Barbin99258a131aed
diff --git a/apps/carbon/app/modules/parts/parts.models.ts b/apps/carbon/app/modules/parts/parts.models.ts
index 50e6c056f7..fa9491827f 100644
--- a/apps/carbon/app/modules/parts/parts.models.ts
+++ b/apps/carbon/app/modules/parts/parts.models.ts
@@ -149,18 +149,15 @@ export const partUnitSalePriceValidator = z.object({
export const serviceValidator = z.object({
id: z.string().min(1, { message: "Service ID is required" }).max(255),
- 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",
}),
}),
- blocked: zfd.checkbox(),
- active: zfd.checkbox(),
});
+export const newServiceValidator = itemValidator.merge(serviceValidator);
+
export const serviceSupplierValidator = z.object({
id: zfd.text(z.string().optional()),
serviceId: z.string().min(1, { message: "Part ID is required" }),
diff --git a/apps/carbon/app/modules/parts/parts.service.ts b/apps/carbon/app/modules/parts/parts.service.ts
index bd1e5db83b..6eb9ea70c6 100644
--- a/apps/carbon/app/modules/parts/parts.service.ts
+++ b/apps/carbon/app/modules/parts/parts.service.ts
@@ -6,7 +6,9 @@ import type { GenericQueryFilters } from "~/utils/query";
import { setGenericQueryFilters } from "~/utils/query";
import { sanitize } from "~/utils/supabase";
import type {
+ itemValidator,
newPartValidator,
+ newServiceValidator,
partCostValidator,
partGroupValidator,
partInventoryValidator,
@@ -494,6 +496,20 @@ export async function upsertPart(
.eq("id", part.id);
}
+export async function updateItem(
+ client: SupabaseClient<Database>,
+ item: z.infer<typeof itemValidator> & {
+ companyId: string;
+ type: Database["public"]["Enums"]["itemType"];
+ }
+) {
+ return client
+ .from("item")
+ .update(sanitize(item))
+ .eq("id", item.id)
+ .eq("companyId", item.companyId);
+}
+
export async function upsertPartCost(
client: SupabaseClient<Database>,
partCost: z.infer<typeof partCostValidator> & {
@@ -653,7 +669,7 @@ export async function upsertPartUnitSalePrice(
export async function upsertService(
client: SupabaseClient<Database>,
service:
- | (z.infer<typeof serviceValidator> & {
+ | (z.infer<typeof newServiceValidator> & {
companyId: string;
createdBy: string;
customFields?: Json;
@@ -665,7 +681,31 @@ export async function upsertService(
})
) {
if ("createdBy" in service) {
- return client.from("service").insert(service).select("*").single();
+ const itemInsert = await client
+ .from("item")
+ .insert({
+ readableId: service.id,
+ name: service.name,
+ type: "service",
+ companyId: service.companyId,
+ createdBy: service.createdBy,
+ })
+ .select("id")
+ .single();
+ if (itemInsert.error) return itemInsert;
+ const itemId = itemInsert.data?.id;
+
+ return client
+ .from("service")
+ .insert({
+ id: service.id,
+ itemId: itemId,
+ serviceType: service.serviceType,
+ companyId: service.companyId,
+ createdBy: service.createdBy,
+ })
+ .select("*")
+ .single();
}
return client
.from("service")
diff --git a/apps/carbon/app/modules/parts/ui/Item/ItemForm.tsx b/apps/carbon/app/modules/parts/ui/Item/ItemForm.tsx
index 53a9a16c74..960a58cf96 100644
--- a/apps/carbon/app/modules/parts/ui/Item/ItemForm.tsx
+++ b/apps/carbon/app/modules/parts/ui/Item/ItemForm.tsx
@@ -7,6 +7,7 @@ import {
CardTitle,
} from "@carbon/react";
import { ValidatedForm } from "@carbon/remix-validated-form";
+import { useFetcher } from "@remix-run/react";
import type { z } from "zod";
import {
Boolean,
@@ -32,14 +33,16 @@ function getLabel(type: Database["public"]["Enums"]["itemType"]) {
const ItemForm = ({ initialValues, type }: ItemFormProps) => {
const permissions = usePermissions();
+ const fetcher = useFetcher();
return (
<Card>
<ValidatedForm
- action={path.to.item}
+ action={path.to.api.item(type)}
method="post"
validator={itemValidator}
defaultValues={initialValues}
+ fetcher={fetcher}
>
<CardHeader>
<CardTitle>{getLabel(type)}</CardTitle>
diff --git a/apps/carbon/app/modules/parts/ui/Part/PartForm.tsx b/apps/carbon/app/modules/parts/ui/Part/PartForm.tsx
index 99968e50d1..709823e212 100644
--- a/apps/carbon/app/modules/parts/ui/Part/PartForm.tsx
+++ b/apps/carbon/app/modules/parts/ui/Part/PartForm.tsx
@@ -147,6 +147,7 @@ const PartForm = ({ initialValues, type = "card", onClose }: PartFormProps) => {
</ModalCardHeader>
<ModalCardBody>
<Hidden name="type" value={type} />
+ {isEditing && <Hidden name="id" />}
<div
className={cn(
"grid w-full gap-x-8 gap-y-2",
diff --git a/apps/carbon/app/modules/parts/ui/Service/ServiceForm.tsx b/apps/carbon/app/modules/parts/ui/Service/ServiceForm.tsx
index 65b379e8ad..52846be8d7 100644
--- a/apps/carbon/app/modules/parts/ui/Service/ServiceForm.tsx
+++ b/apps/carbon/app/modules/parts/ui/Service/ServiceForm.tsx
@@ -13,6 +13,7 @@ import type { z } from "zod";
import {
Boolean,
CustomFormFields,
+ Hidden,
Input,
InputControlled,
PartGroup,
@@ -22,7 +23,11 @@ import {
} from "~/components/Form";
import { usePermissions, useUser } from "~/hooks";
import { useSupabase } from "~/lib/supabase";
-import { serviceType, serviceValidator } from "~/modules/parts";
+import {
+ newServiceValidator,
+ serviceType,
+ serviceValidator,
+} from "~/modules/parts";
type ServiceFormProps = {
initialValues: z.infer<typeof serviceValidator>;
@@ -90,7 +95,7 @@ const ServiceForm = ({ initialValues }: ServiceFormProps) => {
return (
<ValidatedForm
method="post"
- validator={serviceValidator}
+ validator={isEditing ? serviceValidator : newServiceValidator}
defaultValues={initialValues}
>
<Card>
@@ -104,27 +109,29 @@ const ServiceForm = ({ initialValues }: ServiceFormProps) => {
)}
</CardHeader>
<CardContent>
+ {isEditing && <Hidden name="id" />}
<div
className={cn(
"grid w-full gap-x-8 gap-y-2",
isEditing ? "grid-cols-1 lg:grid-cols-3" : "grid-cols-1"
)}
>
- {isEditing ? (
- <Input name="id" label="Service ID" isReadOnly />
- ) : (
- <InputControlled
- name="id"
- label="Service ID"
- helperText="Use ... to get the next service ID"
- value={serviceId}
- onChange={onServiceIdChange}
- isDisabled={loading}
- />
+ {!isEditing && (
+ <>
+ {" "}
+ <InputControlled
+ name="id"
+ label="Service ID"
+ helperText="Use ... to get the next service ID"
+ value={serviceId}
+ onChange={onServiceIdChange}
+ isDisabled={loading}
+ />
+ <Input name="name" label="Name" />
+ <PartGroup name="partGroupId" label="Part Group" />
+ <TextArea name="description" label="Description" />
+ </>
)}
- <Input name="name" label="Name" />
- <PartGroup name="partGroupId" label="Part Group" />
- <TextArea name="description" label="Description" />
<Select
name="serviceType"
@@ -132,8 +139,8 @@ const ServiceForm = ({ initialValues }: ServiceFormProps) => {
options={serviceTypeOptions}
/>
- <Boolean name="blocked" label="Blocked" />
- {isEditing && <Boolean name="active" label="Active" />}
+ {!isEditing && <Boolean name="blocked" label="Blocked" />}
+
<CustomFormFields table="service" />
</div>
</CardContent>
diff --git a/apps/carbon/app/routes/api+/item.$type.ts b/apps/carbon/app/routes/api+/item.$type.ts
new file mode 100644
index 0000000000..17345eb00a
--- /dev/null
+++ b/apps/carbon/app/routes/api+/item.$type.ts
@@ -0,0 +1,52 @@
+import { validationError, validator } from "@carbon/remix-validated-form";
+import { json, type ActionFunctionArgs } from "@remix-run/node";
+import { itemValidator, updateItem } from "~/modules/parts";
+import { requirePermissions } from "~/services/auth/auth.server";
+import { flash } from "~/services/session.server";
+import { assertIsPost } from "~/utils/http";
+import { error, success } from "~/utils/result";
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client, companyId } = await requirePermissions(request, {
+ create: "parts",
+ });
+
+ const { type } = params;
+ if (!type) throw new Error("Could not find type");
+ if (
+ ![
+ "part",
+ "material",
+ "tool",
+ "hardware",
+ "service",
+ "consumable",
+ "fixture",
+ ].includes(type)
+ ) {
+ throw new Error("Invalid type");
+ }
+
+ const formData = await request.formData();
+ const validation = await validator(itemValidator).validate(formData);
+
+ if (validation.error) {
+ return validationError(validation.error);
+ }
+
+ const update = await updateItem(client, {
+ ...validation.data,
+ type: type as "part",
+ companyId,
+ });
+
+ if (update.error) {
+ return json(
+ update.error,
+ await flash(request, error(update.error, "Failed to update item"))
+ );
+ }
+
+ return json({ success: true }, await flash(request, success("Updated item")));
+}
diff --git a/apps/carbon/app/routes/x+/service+/$serviceId.details.tsx b/apps/carbon/app/routes/x+/service+/$serviceId.details.tsx
index 26016c3b2a..12f28fbeff 100644
--- a/apps/carbon/app/routes/x+/service+/$serviceId.details.tsx
+++ b/apps/carbon/app/routes/x+/service+/$serviceId.details.tsx
@@ -1,10 +1,16 @@
+import { VStack } from "@carbon/react";
import { validationError, validator } from "@carbon/remix-validated-form";
import type { ActionFunctionArgs } from "@remix-run/node";
import { redirect } from "@remix-run/node";
import { useParams } from "@remix-run/react";
import { useRouteData } from "~/hooks";
import type { Service } from "~/modules/parts";
-import { ServiceForm, serviceValidator, upsertService } from "~/modules/parts";
+import {
+ ItemForm,
+ ServiceForm,
+ serviceValidator,
+ upsertService,
+} from "~/modules/parts";
import { requirePermissions } from "~/services/auth/auth.server";
import { flash } from "~/services/session.server";
import { getCustomFields, setCustomFields } from "~/utils/form";
@@ -56,7 +62,17 @@ export default function ServiceDetailsRoute() {
);
if (!routeData) throw new Error("Could not find part data");
- const initialValues = {
+ const itemInitialValues = {
+ id: routeData.service?.itemId ?? "",
+ readableId: routeData.service?.id ?? "",
+ name: routeData.service?.name ?? "",
+ description: routeData.service?.description ?? "",
+ partGroupId: routeData.service?.partGroupId ?? "",
+ active: routeData.service?.active ?? true,
+ blocked: routeData.service?.blocked ?? false,
+ };
+
+ const serviceInitialValues = {
id: routeData.service?.id!,
name: routeData.service?.name ?? "",
description: routeData.service?.description ?? undefined,
@@ -67,5 +83,17 @@ export default function ServiceDetailsRoute() {
...getCustomFields(routeData.service?.customFields),
};
- return <ServiceForm key={initialValues.id} initialValues={initialValues} />;
+ return (
+ <VStack spacing={4}>
+ <ItemForm
+ key={itemInitialValues.id}
+ initialValues={itemInitialValues}
+ type="service"
+ />
+ <ServiceForm
+ key={serviceInitialValues.id}
+ initialValues={serviceInitialValues}
+ />
+ </VStack>
+ );
}
diff --git a/apps/carbon/app/routes/x+/service+/new.tsx b/apps/carbon/app/routes/x+/service+/new.tsx
index d533d785dc..8718530ba8 100644
--- a/apps/carbon/app/routes/x+/service+/new.tsx
+++ b/apps/carbon/app/routes/x+/service+/new.tsx
@@ -1,7 +1,11 @@
import { validationError, validator } from "@carbon/remix-validated-form";
import type { ActionFunctionArgs } from "@remix-run/node";
import { redirect } from "@remix-run/node";
-import { ServiceForm, serviceValidator, upsertService } from "~/modules/parts";
+import {
+ ServiceForm,
+ newServiceValidator,
+ upsertService,
+} from "~/modules/parts";
import { requirePermissions } from "~/services/auth/auth.server";
import { flash } from "~/services/session.server";
import { setCustomFields } from "~/utils/form";
@@ -22,7 +26,7 @@ export async function action({ request }: ActionFunctionArgs) {
});
const formData = await request.formData();
- const validation = await validator(serviceValidator).validate(formData);
+ const validation = await validator(newServiceValidator).validate(formData);
if (validation.error) {
return validationError(validation.error);
diff --git a/apps/carbon/app/routes/x+/item+/index.tsx b/apps/carbon/app/routes/x+/wip+/index.tsx
similarity index 100%
rename from apps/carbon/app/routes/x+/item+/index.tsx
rename to apps/carbon/app/routes/x+/wip+/index.tsx
diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.ts
index 873d9add47..0d95b4f1a9 100644
--- a/apps/carbon/app/utils/path.ts
+++ b/apps/carbon/app/utils/path.ts
@@ -28,6 +28,7 @@ export const path = {
equipmentTypes: `${api}/resources/equipment-types`,
groupsByType: (type?: string) =>
generatePath(`${api}/users/groups?type=${type}`),
+ item: (type: string) => generatePath(`${api}/item/${type}`),
locations: `${api}/resources/locations`,
partGroups: `${api}/parts/groups`,
rollback: (table: string, id: string) =>
@@ -267,7 +268,6 @@ export const path = {
integration: (name: string) =>
generatePath(`${x}/settings/integrations/${name}`),
integrations: `${x}/settings/integrations`,
- item: `${x}/item`,
inventory: `${x}/inventory`,
invoicing: `${x}/invoicing`,
jobs: `${x}/jobs`,
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 66491ff232..7048590ec9 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -14775,60 +14775,48 @@ export type Database = {
}
service: {
Row: {
- active: boolean
approved: boolean
approvedBy: string | null
assignee: string | null
- blocked: boolean
companyId: string
createdAt: string
createdBy: string
customFields: Json | null
- description: string | null
fromDate: string | null
id: string
- name: string
- partGroupId: string | null
+ itemId: string | null
serviceType: Database["public"]["Enums"]["serviceType"]
toDate: string | null
updatedAt: string | null
updatedBy: string | null
}
Insert: {
- active?: boolean
approved?: boolean
approvedBy?: string | null
assignee?: string | null
- blocked?: boolean
companyId: string
createdAt?: string
createdBy: string
customFields?: Json | null
- description?: string | null
fromDate?: string | null
id: string
- name: string
- partGroupId?: string | null
+ itemId?: string | null
serviceType: Database["public"]["Enums"]["serviceType"]
toDate?: string | null
updatedAt?: string | null
updatedBy?: string | null
}
Update: {
- active?: boolean
approved?: boolean
approvedBy?: string | null
assignee?: string | null
- blocked?: boolean
companyId?: string
createdAt?: string
createdBy?: string
customFields?: Json | null
- description?: string | null
fromDate?: string | null
id?: string
- name?: string
- partGroupId?: string | null
+ itemId?: string | null
serviceType?: Database["public"]["Enums"]["serviceType"]
toDate?: string | null
updatedAt?: string | null
@@ -14969,10 +14957,10 @@ export type Database = {
referencedColumns: ["userId"]
},
{
- foreignKeyName: "service_partGroupId_fkey"
- columns: ["partGroupId"]
+ foreignKeyName: "service_itemId_fkey"
+ columns: ["itemId"]
isOneToOne: false
- referencedRelation: "partGroup"
+ referencedRelation: "item"
referencedColumns: ["id"]
},
{
@@ -20296,9 +20284,7 @@ export type Database = {
quantityToReceive: number | null
receivedComplete: boolean | null
requiresInspection: boolean | null
- serviceDescription: string | null
serviceId: string | null
- serviceName: string | null
setupPrice: number | null
shelfId: string | null
supplierId: string | null
@@ -22198,6 +22184,7 @@ export type Database = {
description: string | null
fromDate: string | null
id: string | null
+ itemId: string | null
name: string | null
partGroup: string | null
partGroupId: string | null
@@ -22208,6 +22195,13 @@ export type Database = {
updatedBy: string | null
}
Relationships: [
+ {
+ foreignKeyName: "item_partGroupId_fkey"
+ columns: ["partGroupId"]
+ isOneToOne: false
+ referencedRelation: "partGroup"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "service_approvedBy_fkey"
columns: ["approvedBy"]
@@ -22342,10 +22336,10 @@ export type Database = {
referencedColumns: ["userId"]
},
{
- foreignKeyName: "service_partGroupId_fkey"
- columns: ["partGroupId"]
+ foreignKeyName: "service_itemId_fkey"
+ columns: ["itemId"]
isOneToOne: false
- referencedRelation: "partGroup"
+ referencedRelation: "item"
referencedColumns: ["id"]
},
{
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 66491ff232..7048590ec9 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -14775,60 +14775,48 @@ export type Database = {
}
service: {
Row: {
- active: boolean
approved: boolean
approvedBy: string | null
assignee: string | null
- blocked: boolean
companyId: string
createdAt: string
createdBy: string
customFields: Json | null
- description: string | null
fromDate: string | null
id: string
- name: string
- partGroupId: string | null
+ itemId: string | null
serviceType: Database["public"]["Enums"]["serviceType"]
toDate: string | null
updatedAt: string | null
updatedBy: string | null
}
Insert: {
- active?: boolean
approved?: boolean
approvedBy?: string | null
assignee?: string | null
- blocked?: boolean
companyId: string
createdAt?: string
createdBy: string
customFields?: Json | null
- description?: string | null
fromDate?: string | null
id: string
- name: string
- partGroupId?: string | null
+ itemId?: string | null
serviceType: Database["public"]["Enums"]["serviceType"]
toDate?: string | null
updatedAt?: string | null
updatedBy?: string | null
}
Update: {
- active?: boolean
approved?: boolean
approvedBy?: string | null
assignee?: string | null
- blocked?: boolean
companyId?: string
createdAt?: string
createdBy?: string
customFields?: Json | null
- description?: string | null
fromDate?: string | null
id?: string
- name?: string
- partGroupId?: string | null
+ itemId?: string | null
serviceType?: Database["public"]["Enums"]["serviceType"]
toDate?: string | null
updatedAt?: string | null
@@ -14969,10 +14957,10 @@ export type Database = {
referencedColumns: ["userId"]
},
{
- foreignKeyName: "service_partGroupId_fkey"
- columns: ["partGroupId"]
+ foreignKeyName: "service_itemId_fkey"
+ columns: ["itemId"]
isOneToOne: false
- referencedRelation: "partGroup"
+ referencedRelation: "item"
referencedColumns: ["id"]
},
{
@@ -20296,9 +20284,7 @@ export type Database = {
quantityToReceive: number | null
receivedComplete: boolean | null
requiresInspection: boolean | null
- serviceDescription: string | null
serviceId: string | null
- serviceName: string | null
setupPrice: number | null
shelfId: string | null
supplierId: string | null
@@ -22198,6 +22184,7 @@ export type Database = {
description: string | null
fromDate: string | null
id: string | null
+ itemId: string | null
name: string | null
partGroup: string | null
partGroupId: string | null
@@ -22208,6 +22195,13 @@ export type Database = {
updatedBy: string | null
}
Relationships: [
+ {
+ foreignKeyName: "item_partGroupId_fkey"
+ columns: ["partGroupId"]
+ isOneToOne: false
+ referencedRelation: "partGroup"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "service_approvedBy_fkey"
columns: ["approvedBy"]
@@ -22342,10 +22336,10 @@ export type Database = {
referencedColumns: ["userId"]
},
{
- foreignKeyName: "service_partGroupId_fkey"
- columns: ["partGroupId"]
+ foreignKeyName: "service_itemId_fkey"
+ columns: ["itemId"]
isOneToOne: false
- referencedRelation: "partGroup"
+ referencedRelation: "item"
referencedColumns: ["id"]
},
{
diff --git a/packages/database/supabase/migrations/20230330024716_parts.sql b/packages/database/supabase/migrations/20230330024716_parts.sql
index 53f552f613..0acb09b171 100644
--- a/packages/database/supabase/migrations/20230330024716_parts.sql
+++ b/packages/database/supabase/migrations/20230330024716_parts.sql
@@ -83,6 +83,7 @@ CREATE TABLE "item" (
CREATE INDEX "item_companyId_idx" ON "item" ("companyId");
CREATE INDEX "item_name_companyId_idx" ON "item" ("name", "companyId");
+CREATE INDEX "item_type_companyId_idx" ON "item" ("type", "companyId");
CREATE TYPE "partType" AS ENUM (
'Inventory',
diff --git a/packages/database/supabase/migrations/20230412120726_services.sql b/packages/database/supabase/migrations/20230412120726_services.sql
index 6c58929a93..373648e3fc 100644
--- a/packages/database/supabase/migrations/20230412120726_services.sql
+++ b/packages/database/supabase/migrations/20230412120726_services.sql
@@ -5,12 +5,8 @@ CREATE TYPE "serviceType" AS ENUM (
CREATE TABLE "service" (
"id" TEXT NOT NULL,
- "name" TEXT NOT NULL,
- "description" TEXT,
- "blocked" BOOLEAN NOT NULL DEFAULT false,
- "partGroupId" TEXT,
+ "itemId" TEXT,
"serviceType" "serviceType" NOT NULL,
- "active" BOOLEAN NOT NULL DEFAULT true,
"approved" BOOLEAN NOT NULL DEFAULT false,
"approvedBy" TEXT,
"fromDate" DATE,
@@ -24,7 +20,7 @@ CREATE TABLE "service" (
"updatedAt" TIMESTAMP WITH TIME ZONE,
CONSTRAINT "service_pkey" PRIMARY KEY ("id", "companyId"),
- CONSTRAINT "service_partGroupId_fkey" FOREIGN KEY ("partGroupId") REFERENCES "partGroup"("id") ON DELETE SET NULL ON UPDATE CASCADE,
+ CONSTRAINT "service_itemId_fkey" FOREIGN KEY ("itemId") REFERENCES "item"("id") ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT "service_assignee_fkey" FOREIGN KEY ("assignee") REFERENCES "user"("id") ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT "service_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id"),
CONSTRAINT "service_approvedBy_fkey" FOREIGN KEY ("approvedBy") REFERENCES "user"("id"),
@@ -33,6 +29,8 @@ CREATE TABLE "service" (
);
CREATE INDEX "service_companyId_idx" ON "service"("companyId");
+CREATE INDEX "service_itemId_idx" ON "service"("itemId");
+CREATE INDEX "service_serviceType_idx" ON "service"("serviceType", "companyId");
CREATE POLICY "Employees can view services" ON "service"
FOR SELECT
@@ -145,12 +143,13 @@ CREATE POLICY "Suppliers with parts_update can update their own part suppliers"
CREATE OR REPLACE VIEW "services" WITH(SECURITY_INVOKER=true) AS
SELECT
s."id",
- s."name",
- s."description",
- s."blocked",
- s."partGroupId",
+ s."itemId",
+ i."name",
+ i."description",
+ i."blocked",
+ i."partGroupId",
s."serviceType",
- s."active",
+ i."active",
s."approved",
s."approvedBy",
s."fromDate",
@@ -160,16 +159,18 @@ CREATE OR REPLACE VIEW "services" WITH(SECURITY_INVOKER=true) AS
pg.name AS "partGroup",
array_agg(ss."supplierId") AS "supplierIds"
FROM "service" s
- LEFT JOIN "partGroup" pg ON pg.id = s."partGroupId"
+ INNER JOIN "item" i ON i."id" = s."itemId"
+ LEFT JOIN "partGroup" pg ON pg.id = i."partGroupId"
LEFT JOIN "serviceSupplier" ss ON ss."serviceId" = s.id
GROUP BY
s."id",
- s."name",
- s."description",
- s."blocked",
- s."partGroupId",
+ s."itemId",
+ i."name",
+ i."description",
+ i."blocked",
+ i."partGroupId",
+ i."active",
s."serviceType",
- s."active",
s."approved",
s."approvedBy",
s."fromDate",
diff --git a/packages/database/supabase/migrations/20231222200612_purchase-order-document.sql b/packages/database/supabase/migrations/20231222200612_purchase-order-document.sql
index 20b5da79c1..41250cbc38 100644
--- a/packages/database/supabase/migrations/20231222200612_purchase-order-document.sql
+++ b/packages/database/supabase/migrations/20231222200612_purchase-order-document.sql
@@ -5,8 +5,8 @@ CREATE OR REPLACE VIEW "purchaseOrderLines" WITH(SECURITY_INVOKER=true) AS
-- p.name AS "partName",
-- p.description AS "partDescription",
ps."supplierPartId",
- s.name AS "serviceName",
- s.description AS "serviceDescription",
+ -- s.name AS "serviceName",
+ -- s.description AS "serviceDescription",
ss."supplierServiceId"
FROM "purchaseOrderLine" pol
INNER JOIN "purchaseOrder" po
diff --git a/packages/database/supabase/migrations/20240324175747_assignee.sql b/packages/database/supabase/migrations/20240324175747_assignee.sql
index 15e18fe1c1..6825feff80 100644
--- a/packages/database/supabase/migrations/20240324175747_assignee.sql
+++ b/packages/database/supabase/migrations/20240324175747_assignee.sql
@@ -146,10 +146,16 @@ DROP VIEW "services";
CREATE OR REPLACE VIEW "services" WITH(SECURITY_INVOKER=true) AS
SELECT
s.*,
+ i.name,
+ i.description,
+ i."partGroupId",
+ i.active,
+ i.blocked,
pg.name AS "partGroup",
ss."supplierIds"
FROM "service" s
- LEFT JOIN "partGroup" pg ON pg.id = s."partGroupId"
+ INNER JOIN "item" i ON i.id = s."itemId"
+ LEFT JOIN "partGroup" pg ON pg.id = i."partGroupId"
LEFT JOIN (
SELECT
"serviceId",
diff --git a/packages/database/supabase/migrations/20240402052512_purchasing-conversion-factors.sql b/packages/database/supabase/migrations/20240402052512_purchasing-conversion-factors.sql
index 4513e3793f..6ff55ca438 100644
--- a/packages/database/supabase/migrations/20240402052512_purchasing-conversion-factors.sql
+++ b/packages/database/supabase/migrations/20240402052512_purchasing-conversion-factors.sql
@@ -13,8 +13,8 @@ CREATE OR REPLACE VIEW "purchaseOrderLines" WITH(SECURITY_INVOKER=true) AS
-- p.name AS "partName",
-- p.description AS "partDescription",
ps."supplierPartId",
- s.name AS "serviceName",
- s.description AS "serviceDescription",
+ -- s.name AS "serviceName",
+ -- s.description AS "serviceDescription",
ss."supplierServiceId"
FROM "purchaseOrderLine" pol
INNER JOIN "purchaseOrder" po