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 assignee to service

Brad Barbin9c83e1195329
diff --git a/apps/carbon/app/modules/parts/parts.service.ts b/apps/carbon/app/modules/parts/parts.service.ts
index 494762667f..1fcc3f1fef 100644
--- a/apps/carbon/app/modules/parts/parts.service.ts
+++ b/apps/carbon/app/modules/parts/parts.service.ts
@@ -540,7 +540,13 @@ export async function upsertService(
if ("createdBy" in service) {
return client.from("service").insert(service).select("*").single();
}
- return client.from("service").update(sanitize(service)).eq("id", service.id);
+ return client
+ .from("service")
+ .update({
+ ...sanitize(service),
+ updatedAt: today(getLocalTimeZone()).toString(),
+ })
+ .eq("id", service.id);
}
export async function upsertServiceSupplier(
diff --git a/apps/carbon/app/modules/parts/ui/Parts/PartsTable.tsx b/apps/carbon/app/modules/parts/ui/Parts/PartsTable.tsx
index 86abf7d4b2..685c74c7b0 100644
--- a/apps/carbon/app/modules/parts/ui/Parts/PartsTable.tsx
+++ b/apps/carbon/app/modules/parts/ui/Parts/PartsTable.tsx
@@ -101,6 +101,22 @@ const PartsTable = memo(({ data, count, partGroups }: PartsTableProps) => {
{ value: "false", label: "Inactive" },
],
},
+ pluralHeader: "Active Statuses",
+ },
+ },
+ {
+ accessorKey: "blocked",
+ header: "Blocked",
+ cell: (item) => <Checkbox isChecked={item.getValue<boolean>()} />,
+ meta: {
+ filter: {
+ type: "static",
+ options: [
+ { value: "true", label: "Blocked" },
+ { value: "false", label: "Not Blocked" },
+ ],
+ },
+ pluralHeader: "Blocked Statuses",
},
},
{
diff --git a/apps/carbon/app/modules/parts/ui/Service/ServiceHeader.tsx b/apps/carbon/app/modules/parts/ui/Service/ServiceHeader.tsx
new file mode 100644
index 0000000000..0952f57b6b
--- /dev/null
+++ b/apps/carbon/app/modules/parts/ui/Service/ServiceHeader.tsx
@@ -0,0 +1,94 @@
+import {
+ Card,
+ CardAction,
+ CardAttribute,
+ CardAttributeLabel,
+ CardAttributeValue,
+ CardAttributes,
+ CardContent,
+ CardDescription,
+ CardHeader,
+ CardTitle,
+ Enumerable,
+ HStack,
+ Menubar,
+ VStack,
+} from "@carbon/react";
+
+import { useParams } from "@remix-run/react";
+import { Assign, EmployeeAvatar, useOptimisticAssignment } from "~/components";
+import { usePermissions, useRouteData } from "~/hooks";
+import type { Service } from "~/modules/parts";
+import { path } from "~/utils/path";
+
+const ServiceHeader = () => {
+ const permissions = usePermissions();
+ const { serviceId } = useParams();
+ if (!serviceId) throw new Error("serviceId not found");
+
+ const routeData = useRouteData<{ service: Service }>(
+ path.to.service(serviceId)
+ );
+
+ const optimisticAssignment = useOptimisticAssignment({
+ id: serviceId,
+ table: "service",
+ });
+ const assignee =
+ optimisticAssignment !== undefined
+ ? optimisticAssignment
+ : routeData?.service?.assignee;
+
+ return (
+ <VStack>
+ {permissions.is("employee") && (
+ <Menubar>
+ <Assign
+ id={serviceId}
+ table="service"
+ value={routeData?.service?.assignee ?? ""}
+ />
+ </Menubar>
+ )}
+ <Card>
+ <HStack className="justify-between items-start">
+ <CardHeader>
+ <CardTitle>{routeData?.service?.id}</CardTitle>
+ <CardDescription>{routeData?.service?.name}</CardDescription>
+ </CardHeader>
+ <CardAction>
+ {/* <Button
+ variant="secondary"
+ onClick={() => alert("TODO")}
+ leftIcon={<FaHistory />}
+ >
+ View History
+ </Button> */}
+ </CardAction>
+ </HStack>
+ <CardContent>
+ <CardAttributes>
+ <CardAttribute>
+ <CardAttributeLabel>Assignee</CardAttributeLabel>
+ <CardAttributeValue>
+ {assignee ? (
+ <EmployeeAvatar employeeId={assignee ?? null} />
+ ) : (
+ "-"
+ )}
+ </CardAttributeValue>
+ </CardAttribute>
+ <CardAttribute>
+ <CardAttributeLabel>Service Type</CardAttributeLabel>
+ <CardAttributeValue>
+ <Enumerable value={routeData?.service?.serviceType ?? null} />
+ </CardAttributeValue>
+ </CardAttribute>
+ </CardAttributes>
+ </CardContent>
+ </Card>
+ </VStack>
+ );
+};
+
+export default ServiceHeader;
diff --git a/apps/carbon/app/modules/parts/ui/Service/ServicePreview.tsx b/apps/carbon/app/modules/parts/ui/Service/ServicePreview.tsx
deleted file mode 100644
index 11d8d30a32..0000000000
--- a/apps/carbon/app/modules/parts/ui/Service/ServicePreview.tsx
+++ /dev/null
@@ -1,64 +0,0 @@
-import {
- Card,
- CardAction,
- CardAttribute,
- CardAttributeLabel,
- CardAttributeValue,
- CardAttributes,
- CardContent,
- CardDescription,
- CardHeader,
- CardTitle,
- HStack,
-} from "@carbon/react";
-import { useParams } from "@remix-run/react";
-import { useRouteData } from "~/hooks";
-import type { Service } from "~/modules/parts";
-import { path } from "~/utils/path";
-
-const ServicePreview = () => {
- const { serviceId } = useParams();
- if (!serviceId) throw new Error("serviceId not found");
-
- const routeData = useRouteData<{ service: Service }>(
- path.to.service(serviceId)
- );
-
- return (
- <Card>
- <HStack className="justify-between items-start">
- <CardHeader>
- <CardTitle>{routeData?.service?.name}</CardTitle>
- <CardDescription>{routeData?.service?.description}</CardDescription>
- </CardHeader>
- <CardAction>
- {/* <Button
- variant="secondary"
- onClick={() => alert("TODO")}
- leftIcon={<FaHistory />}
- >
- View History
- </Button> */}
- </CardAction>
- </HStack>
- <CardContent>
- <CardAttributes>
- <CardAttribute>
- <CardAttributeLabel>Type</CardAttributeLabel>
- <CardAttributeValue>
- {routeData?.service?.serviceType}
- </CardAttributeValue>
- </CardAttribute>
- <CardAttribute>
- <CardAttributeLabel>Part Group</CardAttributeLabel>
- <CardAttributeValue>
- {routeData?.service?.partGroup}
- </CardAttributeValue>
- </CardAttribute>
- </CardAttributes>
- </CardContent>
- </Card>
- );
-};
-
-export default ServicePreview;
diff --git a/apps/carbon/app/modules/parts/ui/Service/index.ts b/apps/carbon/app/modules/parts/ui/Service/index.ts
index 885a53d6f0..4542163a4e 100644
--- a/apps/carbon/app/modules/parts/ui/Service/index.ts
+++ b/apps/carbon/app/modules/parts/ui/Service/index.ts
@@ -1,12 +1,12 @@
import ServiceForm from "./ServiceForm";
-import ServicePreview from "./ServicePreview";
+import ServiceHeader from "./ServiceHeader";
import ServiceSidebar from "./ServiceSidebar";
import ServiceSupplierForm from "./ServiceSupplierForm";
import ServiceSuppliers from "./ServiceSuppliers";
export {
ServiceForm,
- ServicePreview,
+ ServiceHeader,
ServiceSidebar,
ServiceSupplierForm,
ServiceSuppliers,
diff --git a/apps/carbon/app/modules/parts/ui/Services/ServicesTable.tsx b/apps/carbon/app/modules/parts/ui/Services/ServicesTable.tsx
index 073f4d658e..3f5baf1a7d 100644
--- a/apps/carbon/app/modules/parts/ui/Services/ServicesTable.tsx
+++ b/apps/carbon/app/modules/parts/ui/Services/ServicesTable.tsx
@@ -1,28 +1,31 @@
-import { Enumerable, MenuIcon, MenuItem } from "@carbon/react";
+import { Checkbox, Enumerable, MenuIcon, MenuItem } from "@carbon/react";
+import { formatDate } from "@carbon/utils";
import { useNavigate } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
import { memo, useMemo } from "react";
import { BsFillPenFill } from "react-icons/bs";
-import { Hyperlink, New, Table } from "~/components";
-import { usePermissions, useUrlParams } from "~/hooks";
+import { EmployeeAvatar, Hyperlink, New, Table } from "~/components";
+import { usePermissions } from "~/hooks";
import { useCustomColumns } from "~/hooks/useCustomColumns";
-import { serviceType, type Service } from "~/modules/parts";
+import type { Service } from "~/modules/parts";
+import { serviceType } from "~/modules/parts";
+import { usePeople } from "~/stores";
import type { ListItem } from "~/types";
import { path } from "~/utils/path";
type ServicesTableProps = {
data: Service[];
- count: number;
partGroups: ListItem[];
+ count: number;
};
const ServicesTable = memo(
({ data, count, partGroups }: ServicesTableProps) => {
const navigate = useNavigate();
- const [params] = useUrlParams();
const permissions = usePermissions();
+ const customColumns = useCustomColumns<Service>("part");
+ const [people] = usePeople();
- const customColumns = useCustomColumns<Service>("service");
const columns = useMemo<ColumnDef<Service>[]>(() => {
const defaultColumns: ColumnDef<Service>[] = [
{
@@ -46,7 +49,7 @@ const ServicesTable = memo(
},
{
accessorKey: "serviceType",
- header: "Type",
+ header: "Service Type",
cell: (item) => <Enumerable value={item.getValue<string>()} />,
meta: {
filter: {
@@ -59,9 +62,8 @@ const ServicesTable = memo(
},
},
{
- // @ts-ignore
accessorKey: "partGroup",
- header: "Part Group",
+ header: "Service Group",
cell: (item) => <Enumerable value={item.getValue<string>()} />,
meta: {
filter: {
@@ -73,15 +75,102 @@ const ServicesTable = memo(
},
},
},
+ {
+ accessorKey: "active",
+ header: "Active",
+ cell: (item) => <Checkbox isChecked={item.getValue<boolean>()} />,
+ meta: {
+ filter: {
+ type: "static",
+ options: [
+ { value: "true", label: "Active" },
+ { value: "false", label: "Inactive" },
+ ],
+ },
+ pluralHeader: "Active Statuses",
+ },
+ },
+ {
+ accessorKey: "blocked",
+ header: "Blocked",
+ cell: (item) => <Checkbox isChecked={item.getValue<boolean>()} />,
+ meta: {
+ filter: {
+ type: "static",
+ options: [
+ { value: "true", label: "Blocked" },
+ { value: "false", label: "Not Blocked" },
+ ],
+ },
+ pluralHeader: "Blocked Statuses",
+ },
+ },
+ {
+ id: "assignee",
+ header: "Assignee",
+ cell: ({ row }) => (
+ <EmployeeAvatar employeeId={row.original.assignee} />
+ ),
+ meta: {
+ filter: {
+ type: "static",
+ options: people.map((employee) => ({
+ value: employee.id,
+ label: employee.name,
+ })),
+ },
+ },
+ },
+ {
+ id: "createdBy",
+ header: "Created By",
+ cell: ({ row }) => (
+ <EmployeeAvatar employeeId={row.original.createdBy} />
+ ),
+ meta: {
+ filter: {
+ type: "static",
+ options: people.map((employee) => ({
+ value: employee.id,
+ label: employee.name,
+ })),
+ },
+ },
+ },
+ {
+ accessorKey: "createdAt",
+ header: "Created At",
+ cell: (item) => formatDate(item.getValue<string>()),
+ },
+ {
+ id: "updatedBy",
+ header: "Updated By",
+ cell: ({ row }) => (
+ <EmployeeAvatar employeeId={row.original.updatedBy} />
+ ),
+ meta: {
+ filter: {
+ type: "static",
+ options: people.map((employee) => ({
+ value: employee.id,
+ label: employee.name,
+ })),
+ },
+ },
+ },
+ {
+ accessorKey: "updatedAt",
+ header: "Created At",
+ cell: (item) => formatDate(item.getValue<string>()),
+ },
];
return [...defaultColumns, ...customColumns];
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [params, customColumns]);
+ }, [customColumns, partGroups, people]);
const renderContextMenu = useMemo(() => {
// eslint-disable-next-line react/display-name
return (row: Service) => (
- <MenuItem onClick={() => navigate(path.to.service(row.id!))}>
+ <MenuItem onClick={() => navigate(path.to.part(row.id!))}>
<MenuIcon icon={<BsFillPenFill />} />
Edit Service
</MenuItem>
@@ -94,18 +183,31 @@ const ServicesTable = memo(
count={count}
columns={columns}
data={data}
+ defaultColumnPinning={{
+ left: ["id"],
+ }}
+ defaultColumnVisibility={{
+ description: false,
+ active: false,
+ blocked: false,
+ createdBy: false,
+ createdAt: false,
+ updatedBy: false,
+ updatedAt: false,
+ }}
primaryAction={
permissions.can("create", "parts") && (
<New label="Service" to={path.to.newService} />
)
}
renderContextMenu={renderContextMenu}
+ withColumnOrdering
/>
</>
);
}
);
-ServicesTable.displayName = "ServicesTable";
+ServicesTable.displayName = "ServiceTable";
export default ServicesTable;
diff --git a/apps/carbon/app/routes/x+/service+/$serviceId.tsx b/apps/carbon/app/routes/x+/service+/$serviceId.tsx
index 2b948e2c93..1bc81455f0 100644
--- a/apps/carbon/app/routes/x+/service+/$serviceId.tsx
+++ b/apps/carbon/app/routes/x+/service+/$serviceId.tsx
@@ -1,7 +1,7 @@
import type { LoaderFunctionArgs } from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
import { Outlet } from "@remix-run/react";
-import { ServicePreview, ServiceSidebar, getService } from "~/modules/parts";
+import { ServiceHeader, ServiceSidebar, getService } from "~/modules/parts";
import { requirePermissions } from "~/services/auth";
import { flash } from "~/services/session.server";
import type { Handle } from "~/utils/handle";
@@ -38,7 +38,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
export default function ServiceRoute() {
return (
<>
- <ServicePreview />
+ <ServiceHeader />
<div className="grid grid-cols-1 md:grid-cols-[1fr_4fr] h-full w-full gap-4">
<ServiceSidebar />
<Outlet />
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index c721006e15..d7859c02b9 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -10550,6 +10550,7 @@ export type Database = {
active: boolean
approved: boolean
approvedBy: string | null
+ assignee: string | null
blocked: boolean
createdAt: string
createdBy: string
@@ -10568,6 +10569,7 @@ export type Database = {
active?: boolean
approved?: boolean
approvedBy?: string | null
+ assignee?: string | null
blocked?: boolean
createdAt?: string
createdBy: string
@@ -10586,6 +10588,7 @@ export type Database = {
active?: boolean
approved?: boolean
approvedBy?: string | null
+ assignee?: string | null
blocked?: boolean
createdAt?: string
createdBy?: string
@@ -10629,6 +10632,34 @@ export type Database = {
referencedRelation: "userDefaults"
referencedColumns: ["userId"]
},
+ {
+ foreignKeyName: "service_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "service_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "service_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "service_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
{
foreignKeyName: "service_createdBy_fkey"
columns: ["createdBy"]
@@ -15249,7 +15280,10 @@ export type Database = {
active: boolean | null
approved: boolean | null
approvedBy: string | null
+ assignee: string | null
blocked: boolean | null
+ createdAt: string | null
+ createdBy: string | null
customFields: Json | null
description: string | null
fromDate: string | null
@@ -15260,6 +15294,8 @@ export type Database = {
serviceType: Database["public"]["Enums"]["serviceType"] | null
supplierIds: string[] | null
toDate: string | null
+ updatedAt: string | null
+ updatedBy: string | null
}
Relationships: [
{
@@ -15290,6 +15326,62 @@ export type Database = {
referencedRelation: "userDefaults"
referencedColumns: ["userId"]
},
+ {
+ foreignKeyName: "service_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "service_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "service_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "service_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "service_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "service_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "service_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "service_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
{
foreignKeyName: "service_partGroupId_fkey"
columns: ["partGroupId"]
@@ -15297,6 +15389,34 @@ export type Database = {
referencedRelation: "partGroup"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "service_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "service_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "service_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "service_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
]
}
shifts: {
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index c721006e15..d7859c02b9 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -10550,6 +10550,7 @@ export type Database = {
active: boolean
approved: boolean
approvedBy: string | null
+ assignee: string | null
blocked: boolean
createdAt: string
createdBy: string
@@ -10568,6 +10569,7 @@ export type Database = {
active?: boolean
approved?: boolean
approvedBy?: string | null
+ assignee?: string | null
blocked?: boolean
createdAt?: string
createdBy: string
@@ -10586,6 +10588,7 @@ export type Database = {
active?: boolean
approved?: boolean
approvedBy?: string | null
+ assignee?: string | null
blocked?: boolean
createdAt?: string
createdBy?: string
@@ -10629,6 +10632,34 @@ export type Database = {
referencedRelation: "userDefaults"
referencedColumns: ["userId"]
},
+ {
+ foreignKeyName: "service_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "service_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "service_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "service_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
{
foreignKeyName: "service_createdBy_fkey"
columns: ["createdBy"]
@@ -15249,7 +15280,10 @@ export type Database = {
active: boolean | null
approved: boolean | null
approvedBy: string | null
+ assignee: string | null
blocked: boolean | null
+ createdAt: string | null
+ createdBy: string | null
customFields: Json | null
description: string | null
fromDate: string | null
@@ -15260,6 +15294,8 @@ export type Database = {
serviceType: Database["public"]["Enums"]["serviceType"] | null
supplierIds: string[] | null
toDate: string | null
+ updatedAt: string | null
+ updatedBy: string | null
}
Relationships: [
{
@@ -15290,6 +15326,62 @@ export type Database = {
referencedRelation: "userDefaults"
referencedColumns: ["userId"]
},
+ {
+ foreignKeyName: "service_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "service_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "service_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "service_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "service_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "service_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "service_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "service_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
{
foreignKeyName: "service_partGroupId_fkey"
columns: ["partGroupId"]
@@ -15297,6 +15389,34 @@ export type Database = {
referencedRelation: "partGroup"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "service_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "service_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "service_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "service_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
]
}
shifts: {
diff --git a/packages/database/supabase/migrations/20240324175747_assignee.sql b/packages/database/supabase/migrations/20240324175747_assignee.sql
index 851c170d60..cc0ce45099 100644
--- a/packages/database/supabase/migrations/20240324175747_assignee.sql
+++ b/packages/database/supabase/migrations/20240324175747_assignee.sql
@@ -5,7 +5,7 @@ ALTER TABLE "purchaseInvoice" ADD COLUMN "assignee" TEXT REFERENCES "user" ("id"
ALTER TABLE "quote" ADD COLUMN "assignee" TEXT REFERENCES "user" ("id") ON DELETE SET NULL;
ALTER TABLE "receipt" ADD COLUMN "assignee" TEXT REFERENCES "user" ("id") ON DELETE SET NULL;
-- ALTER TABLE "requestForQuote" ADD COLUMN "assignee" TEXT REFERENCES "user" ("id") ON DELETE SET NULL;
--- ALTER TABLE "service" ADD COLUMN "assignee" TEXT REFERENCES "user" ("id") ON DELETE SET NULL;
+ALTER TABLE "service" ADD COLUMN "assignee" TEXT REFERENCES "user" ("id") ON DELETE SET NULL;
ALTER TABLE "supplier" ADD COLUMN "assignee" TEXT REFERENCES "user" ("id") ON DELETE SET NULL;
DROP VIEW "customers";
@@ -168,40 +168,22 @@ CREATE OR REPLACE VIEW "receipts" WITH(SECURITY_INVOKER=true) AS
-- uu."avatarUrl",
-- l."name";
--- DROP VIEW "services";
--- CREATE OR REPLACE VIEW "services" WITH(SECURITY_INVOKER=true) AS
--- SELECT
--- s."id",
--- s."name",
--- s."description",
--- s."blocked",
--- s."partGroupId",
--- s."serviceType",
--- s."active",
--- s."approved",
--- s."approvedBy",
--- s."fromDate",
--- s."toDate",
--- s."customFields",
--- pg.name AS "partGroup",
--- array_agg(ss."supplierId") AS "supplierIds"
--- FROM "service" s
--- 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."blocked",
--- s."partGroupId",
--- s."serviceType",
--- s."active",
--- s."approved",
--- s."approvedBy",
--- s."fromDate",
--- s."toDate",
--- s."customFields",
--- pg.name;
+DROP VIEW "services";
+CREATE OR REPLACE VIEW "services" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ s.*,
+ pg.name AS "partGroup",
+ ss."supplierIds"
+ FROM "service" s
+ LEFT JOIN "partGroup" pg ON pg.id = s."partGroupId"
+ LEFT JOIN (
+ SELECT
+ "serviceId",
+ array_agg(ss."supplierId") AS "supplierIds"
+ FROM "serviceSupplier" ss
+ GROUP BY "serviceId"
+ ) ss ON ss."serviceId" = s.id;
+
DROP VIEW "suppliers";
CREATE OR REPLACE VIEW "suppliers" WITH(SECURITY_INVOKER=true) AS