@unifiedcommerce/plugin-uom 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/routes/uom.d.ts +9 -0
- package/dist/routes/uom.d.ts.map +1 -0
- package/dist/routes/uom.js +65 -0
- package/dist/schema.d.ts +413 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +37 -0
- package/dist/services/uom-service.d.ts +40 -0
- package/dist/services/uom-service.d.ts.map +1 -0
- package/dist/services/uom-service.js +91 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +37 -0
- package/src/index.ts +26 -0
- package/src/routes/uom.ts +72 -0
- package/src/schema.ts +40 -0
- package/src/services/uom-service.ts +111 -0
- package/src/types.ts +6 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,YAAY,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,wBAAgB,SAAS,mDAgBxB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { defineCommercePlugin } from "@unifiedcommerce/core";
|
|
2
|
+
import { unitsOfMeasure, uomConversions, entityUom } from "./schema";
|
|
3
|
+
import { UOMService } from "./services/uom-service";
|
|
4
|
+
import { buildUOMRoutes } from "./routes/uom";
|
|
5
|
+
export { UOMService } from "./services/uom-service";
|
|
6
|
+
export function uomPlugin() {
|
|
7
|
+
return defineCommercePlugin({
|
|
8
|
+
id: "uom",
|
|
9
|
+
version: "1.0.0",
|
|
10
|
+
permissions: [
|
|
11
|
+
{ scope: "uom:admin", description: "Create/edit units, conversions, entity UOM assignments." },
|
|
12
|
+
{ scope: "uom:read", description: "View units, conversions, convert quantities." },
|
|
13
|
+
],
|
|
14
|
+
schema: () => ({ unitsOfMeasure, uomConversions, entityUom }),
|
|
15
|
+
hooks: () => [],
|
|
16
|
+
routes: (ctx) => {
|
|
17
|
+
const db = ctx.database.db;
|
|
18
|
+
if (!db)
|
|
19
|
+
return [];
|
|
20
|
+
return buildUOMRoutes(new UOMService(db), ctx);
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { UOMService } from "../services/uom-service";
|
|
2
|
+
import type { PluginRouteRegistration } from "@unifiedcommerce/core";
|
|
3
|
+
export declare function buildUOMRoutes(service: UOMService, ctx: {
|
|
4
|
+
services?: Record<string, unknown>;
|
|
5
|
+
database?: {
|
|
6
|
+
db: unknown;
|
|
7
|
+
};
|
|
8
|
+
}): PluginRouteRegistration[];
|
|
9
|
+
//# sourceMappingURL=uom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uom.d.ts","sourceRoot":"","sources":["../../src/routes/uom.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAErE,wBAAgB,cAAc,CAC5B,OAAO,EAAE,UAAU,EACnB,GAAG,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,QAAQ,CAAC,EAAE;QAAE,EAAE,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,GACtE,uBAAuB,EAAE,CA+D3B"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { router } from "@unifiedcommerce/core";
|
|
2
|
+
import { z } from "@hono/zod-openapi";
|
|
3
|
+
export function buildUOMRoutes(service, ctx) {
|
|
4
|
+
const r = router("Units of Measure", "/uom", ctx);
|
|
5
|
+
r.post("/units").summary("Create unit").permission("uom:admin")
|
|
6
|
+
.input(z.object({ code: z.string().min(1).max(20), name: z.string().min(1), category: z.enum(["weight", "volume", "length", "count", "area", "time"]), isBaseUnit: z.boolean().optional() }))
|
|
7
|
+
.handler(async ({ input, orgId }) => {
|
|
8
|
+
const body = input;
|
|
9
|
+
const result = await service.createUnit(orgId, body);
|
|
10
|
+
if (!result.ok)
|
|
11
|
+
throw new Error(result.error);
|
|
12
|
+
return result.value;
|
|
13
|
+
});
|
|
14
|
+
r.get("/units").summary("List units").permission("uom:read")
|
|
15
|
+
.query(z.object({ category: z.enum(["weight", "volume", "length", "count", "area", "time"]).optional() }))
|
|
16
|
+
.handler(async ({ query, orgId }) => {
|
|
17
|
+
const q = query;
|
|
18
|
+
const result = await service.listUnits(orgId, q.category);
|
|
19
|
+
if (!result.ok)
|
|
20
|
+
throw new Error(result.error);
|
|
21
|
+
return result.value;
|
|
22
|
+
});
|
|
23
|
+
r.post("/conversions").summary("Create conversion").permission("uom:admin")
|
|
24
|
+
.input(z.object({ fromUnitId: z.string().uuid(), toUnitId: z.string().uuid(), factor: z.number().int().positive() }))
|
|
25
|
+
.handler(async ({ input, orgId }) => {
|
|
26
|
+
const body = input;
|
|
27
|
+
const result = await service.createConversion(orgId, body);
|
|
28
|
+
if (!result.ok)
|
|
29
|
+
throw new Error(result.error);
|
|
30
|
+
return result.value;
|
|
31
|
+
});
|
|
32
|
+
r.get("/conversions").summary("List conversions").permission("uom:read")
|
|
33
|
+
.handler(async ({ orgId }) => {
|
|
34
|
+
const result = await service.listConversions(orgId);
|
|
35
|
+
if (!result.ok)
|
|
36
|
+
throw new Error(result.error);
|
|
37
|
+
return result.value;
|
|
38
|
+
});
|
|
39
|
+
r.post("/convert").summary("Convert quantity").permission("uom:read")
|
|
40
|
+
.input(z.object({ fromUnitId: z.string().uuid(), toUnitId: z.string().uuid(), quantity: z.number().positive() }))
|
|
41
|
+
.handler(async ({ input, orgId }) => {
|
|
42
|
+
const body = input;
|
|
43
|
+
const result = await service.convert(orgId, body);
|
|
44
|
+
if (!result.ok)
|
|
45
|
+
throw new Error(result.error);
|
|
46
|
+
return result.value;
|
|
47
|
+
});
|
|
48
|
+
r.post("/entities/{id}/uom").summary("Set entity UOM").permission("uom:admin")
|
|
49
|
+
.input(z.object({ purchaseUomId: z.string().uuid(), stockUomId: z.string().uuid(), saleUomId: z.string().uuid(), yieldPercentage: z.number().int().min(1).max(100).optional() }))
|
|
50
|
+
.handler(async ({ params, input, orgId }) => {
|
|
51
|
+
const body = input;
|
|
52
|
+
const result = await service.setEntityUom(orgId, { entityId: params.id, ...body });
|
|
53
|
+
if (!result.ok)
|
|
54
|
+
throw new Error(result.error);
|
|
55
|
+
return result.value;
|
|
56
|
+
});
|
|
57
|
+
r.get("/entities/{id}/uom").summary("Get entity UOM").permission("uom:read")
|
|
58
|
+
.handler(async ({ params, orgId }) => {
|
|
59
|
+
const result = await service.getEntityUom(orgId, params.id);
|
|
60
|
+
if (!result.ok)
|
|
61
|
+
throw new Error(result.error);
|
|
62
|
+
return result.value;
|
|
63
|
+
});
|
|
64
|
+
return r.routes();
|
|
65
|
+
}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
export declare const unitsOfMeasure: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
2
|
+
name: "units_of_measure";
|
|
3
|
+
schema: undefined;
|
|
4
|
+
columns: {
|
|
5
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
6
|
+
name: "id";
|
|
7
|
+
tableName: "units_of_measure";
|
|
8
|
+
dataType: "string";
|
|
9
|
+
columnType: "PgUUID";
|
|
10
|
+
data: string;
|
|
11
|
+
driverParam: string;
|
|
12
|
+
notNull: true;
|
|
13
|
+
hasDefault: true;
|
|
14
|
+
isPrimaryKey: true;
|
|
15
|
+
isAutoincrement: false;
|
|
16
|
+
hasRuntimeDefault: false;
|
|
17
|
+
enumValues: undefined;
|
|
18
|
+
baseColumn: never;
|
|
19
|
+
identity: undefined;
|
|
20
|
+
generated: undefined;
|
|
21
|
+
}, {}, {}>;
|
|
22
|
+
organizationId: import("drizzle-orm/pg-core").PgColumn<{
|
|
23
|
+
name: "organization_id";
|
|
24
|
+
tableName: "units_of_measure";
|
|
25
|
+
dataType: "string";
|
|
26
|
+
columnType: "PgText";
|
|
27
|
+
data: string;
|
|
28
|
+
driverParam: string;
|
|
29
|
+
notNull: true;
|
|
30
|
+
hasDefault: false;
|
|
31
|
+
isPrimaryKey: false;
|
|
32
|
+
isAutoincrement: false;
|
|
33
|
+
hasRuntimeDefault: false;
|
|
34
|
+
enumValues: [string, ...string[]];
|
|
35
|
+
baseColumn: never;
|
|
36
|
+
identity: undefined;
|
|
37
|
+
generated: undefined;
|
|
38
|
+
}, {}, {}>;
|
|
39
|
+
code: import("drizzle-orm/pg-core").PgColumn<{
|
|
40
|
+
name: "code";
|
|
41
|
+
tableName: "units_of_measure";
|
|
42
|
+
dataType: "string";
|
|
43
|
+
columnType: "PgText";
|
|
44
|
+
data: string;
|
|
45
|
+
driverParam: string;
|
|
46
|
+
notNull: true;
|
|
47
|
+
hasDefault: false;
|
|
48
|
+
isPrimaryKey: false;
|
|
49
|
+
isAutoincrement: false;
|
|
50
|
+
hasRuntimeDefault: false;
|
|
51
|
+
enumValues: [string, ...string[]];
|
|
52
|
+
baseColumn: never;
|
|
53
|
+
identity: undefined;
|
|
54
|
+
generated: undefined;
|
|
55
|
+
}, {}, {}>;
|
|
56
|
+
name: import("drizzle-orm/pg-core").PgColumn<{
|
|
57
|
+
name: "name";
|
|
58
|
+
tableName: "units_of_measure";
|
|
59
|
+
dataType: "string";
|
|
60
|
+
columnType: "PgText";
|
|
61
|
+
data: string;
|
|
62
|
+
driverParam: string;
|
|
63
|
+
notNull: true;
|
|
64
|
+
hasDefault: false;
|
|
65
|
+
isPrimaryKey: false;
|
|
66
|
+
isAutoincrement: false;
|
|
67
|
+
hasRuntimeDefault: false;
|
|
68
|
+
enumValues: [string, ...string[]];
|
|
69
|
+
baseColumn: never;
|
|
70
|
+
identity: undefined;
|
|
71
|
+
generated: undefined;
|
|
72
|
+
}, {}, {}>;
|
|
73
|
+
category: import("drizzle-orm/pg-core").PgColumn<{
|
|
74
|
+
name: "category";
|
|
75
|
+
tableName: "units_of_measure";
|
|
76
|
+
dataType: "string";
|
|
77
|
+
columnType: "PgText";
|
|
78
|
+
data: "length" | "weight" | "volume" | "count" | "area" | "time";
|
|
79
|
+
driverParam: string;
|
|
80
|
+
notNull: true;
|
|
81
|
+
hasDefault: false;
|
|
82
|
+
isPrimaryKey: false;
|
|
83
|
+
isAutoincrement: false;
|
|
84
|
+
hasRuntimeDefault: false;
|
|
85
|
+
enumValues: ["weight", "volume", "length", "count", "area", "time"];
|
|
86
|
+
baseColumn: never;
|
|
87
|
+
identity: undefined;
|
|
88
|
+
generated: undefined;
|
|
89
|
+
}, {}, {}>;
|
|
90
|
+
isBaseUnit: import("drizzle-orm/pg-core").PgColumn<{
|
|
91
|
+
name: "is_base_unit";
|
|
92
|
+
tableName: "units_of_measure";
|
|
93
|
+
dataType: "boolean";
|
|
94
|
+
columnType: "PgBoolean";
|
|
95
|
+
data: boolean;
|
|
96
|
+
driverParam: boolean;
|
|
97
|
+
notNull: true;
|
|
98
|
+
hasDefault: true;
|
|
99
|
+
isPrimaryKey: false;
|
|
100
|
+
isAutoincrement: false;
|
|
101
|
+
hasRuntimeDefault: false;
|
|
102
|
+
enumValues: undefined;
|
|
103
|
+
baseColumn: never;
|
|
104
|
+
identity: undefined;
|
|
105
|
+
generated: undefined;
|
|
106
|
+
}, {}, {}>;
|
|
107
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
108
|
+
name: "created_at";
|
|
109
|
+
tableName: "units_of_measure";
|
|
110
|
+
dataType: "date";
|
|
111
|
+
columnType: "PgTimestamp";
|
|
112
|
+
data: Date;
|
|
113
|
+
driverParam: string;
|
|
114
|
+
notNull: true;
|
|
115
|
+
hasDefault: true;
|
|
116
|
+
isPrimaryKey: false;
|
|
117
|
+
isAutoincrement: false;
|
|
118
|
+
hasRuntimeDefault: false;
|
|
119
|
+
enumValues: undefined;
|
|
120
|
+
baseColumn: never;
|
|
121
|
+
identity: undefined;
|
|
122
|
+
generated: undefined;
|
|
123
|
+
}, {}, {}>;
|
|
124
|
+
updatedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
125
|
+
name: "updated_at";
|
|
126
|
+
tableName: "units_of_measure";
|
|
127
|
+
dataType: "date";
|
|
128
|
+
columnType: "PgTimestamp";
|
|
129
|
+
data: Date;
|
|
130
|
+
driverParam: string;
|
|
131
|
+
notNull: true;
|
|
132
|
+
hasDefault: true;
|
|
133
|
+
isPrimaryKey: false;
|
|
134
|
+
isAutoincrement: false;
|
|
135
|
+
hasRuntimeDefault: false;
|
|
136
|
+
enumValues: undefined;
|
|
137
|
+
baseColumn: never;
|
|
138
|
+
identity: undefined;
|
|
139
|
+
generated: undefined;
|
|
140
|
+
}, {}, {}>;
|
|
141
|
+
};
|
|
142
|
+
dialect: "pg";
|
|
143
|
+
}>;
|
|
144
|
+
export declare const uomConversions: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
145
|
+
name: "uom_conversions";
|
|
146
|
+
schema: undefined;
|
|
147
|
+
columns: {
|
|
148
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
149
|
+
name: "id";
|
|
150
|
+
tableName: "uom_conversions";
|
|
151
|
+
dataType: "string";
|
|
152
|
+
columnType: "PgUUID";
|
|
153
|
+
data: string;
|
|
154
|
+
driverParam: string;
|
|
155
|
+
notNull: true;
|
|
156
|
+
hasDefault: true;
|
|
157
|
+
isPrimaryKey: true;
|
|
158
|
+
isAutoincrement: false;
|
|
159
|
+
hasRuntimeDefault: false;
|
|
160
|
+
enumValues: undefined;
|
|
161
|
+
baseColumn: never;
|
|
162
|
+
identity: undefined;
|
|
163
|
+
generated: undefined;
|
|
164
|
+
}, {}, {}>;
|
|
165
|
+
organizationId: import("drizzle-orm/pg-core").PgColumn<{
|
|
166
|
+
name: "organization_id";
|
|
167
|
+
tableName: "uom_conversions";
|
|
168
|
+
dataType: "string";
|
|
169
|
+
columnType: "PgText";
|
|
170
|
+
data: string;
|
|
171
|
+
driverParam: string;
|
|
172
|
+
notNull: true;
|
|
173
|
+
hasDefault: false;
|
|
174
|
+
isPrimaryKey: false;
|
|
175
|
+
isAutoincrement: false;
|
|
176
|
+
hasRuntimeDefault: false;
|
|
177
|
+
enumValues: [string, ...string[]];
|
|
178
|
+
baseColumn: never;
|
|
179
|
+
identity: undefined;
|
|
180
|
+
generated: undefined;
|
|
181
|
+
}, {}, {}>;
|
|
182
|
+
fromUnitId: import("drizzle-orm/pg-core").PgColumn<{
|
|
183
|
+
name: "from_unit_id";
|
|
184
|
+
tableName: "uom_conversions";
|
|
185
|
+
dataType: "string";
|
|
186
|
+
columnType: "PgUUID";
|
|
187
|
+
data: string;
|
|
188
|
+
driverParam: string;
|
|
189
|
+
notNull: true;
|
|
190
|
+
hasDefault: false;
|
|
191
|
+
isPrimaryKey: false;
|
|
192
|
+
isAutoincrement: false;
|
|
193
|
+
hasRuntimeDefault: false;
|
|
194
|
+
enumValues: undefined;
|
|
195
|
+
baseColumn: never;
|
|
196
|
+
identity: undefined;
|
|
197
|
+
generated: undefined;
|
|
198
|
+
}, {}, {}>;
|
|
199
|
+
toUnitId: import("drizzle-orm/pg-core").PgColumn<{
|
|
200
|
+
name: "to_unit_id";
|
|
201
|
+
tableName: "uom_conversions";
|
|
202
|
+
dataType: "string";
|
|
203
|
+
columnType: "PgUUID";
|
|
204
|
+
data: string;
|
|
205
|
+
driverParam: string;
|
|
206
|
+
notNull: true;
|
|
207
|
+
hasDefault: false;
|
|
208
|
+
isPrimaryKey: false;
|
|
209
|
+
isAutoincrement: false;
|
|
210
|
+
hasRuntimeDefault: false;
|
|
211
|
+
enumValues: undefined;
|
|
212
|
+
baseColumn: never;
|
|
213
|
+
identity: undefined;
|
|
214
|
+
generated: undefined;
|
|
215
|
+
}, {}, {}>;
|
|
216
|
+
factor: import("drizzle-orm/pg-core").PgColumn<{
|
|
217
|
+
name: "factor";
|
|
218
|
+
tableName: "uom_conversions";
|
|
219
|
+
dataType: "number";
|
|
220
|
+
columnType: "PgInteger";
|
|
221
|
+
data: number;
|
|
222
|
+
driverParam: string | number;
|
|
223
|
+
notNull: true;
|
|
224
|
+
hasDefault: false;
|
|
225
|
+
isPrimaryKey: false;
|
|
226
|
+
isAutoincrement: false;
|
|
227
|
+
hasRuntimeDefault: false;
|
|
228
|
+
enumValues: undefined;
|
|
229
|
+
baseColumn: never;
|
|
230
|
+
identity: undefined;
|
|
231
|
+
generated: undefined;
|
|
232
|
+
}, {}, {}>;
|
|
233
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
234
|
+
name: "created_at";
|
|
235
|
+
tableName: "uom_conversions";
|
|
236
|
+
dataType: "date";
|
|
237
|
+
columnType: "PgTimestamp";
|
|
238
|
+
data: Date;
|
|
239
|
+
driverParam: string;
|
|
240
|
+
notNull: true;
|
|
241
|
+
hasDefault: true;
|
|
242
|
+
isPrimaryKey: false;
|
|
243
|
+
isAutoincrement: false;
|
|
244
|
+
hasRuntimeDefault: false;
|
|
245
|
+
enumValues: undefined;
|
|
246
|
+
baseColumn: never;
|
|
247
|
+
identity: undefined;
|
|
248
|
+
generated: undefined;
|
|
249
|
+
}, {}, {}>;
|
|
250
|
+
};
|
|
251
|
+
dialect: "pg";
|
|
252
|
+
}>;
|
|
253
|
+
export declare const entityUom: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
254
|
+
name: "entity_uom";
|
|
255
|
+
schema: undefined;
|
|
256
|
+
columns: {
|
|
257
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
258
|
+
name: "id";
|
|
259
|
+
tableName: "entity_uom";
|
|
260
|
+
dataType: "string";
|
|
261
|
+
columnType: "PgUUID";
|
|
262
|
+
data: string;
|
|
263
|
+
driverParam: string;
|
|
264
|
+
notNull: true;
|
|
265
|
+
hasDefault: true;
|
|
266
|
+
isPrimaryKey: true;
|
|
267
|
+
isAutoincrement: false;
|
|
268
|
+
hasRuntimeDefault: false;
|
|
269
|
+
enumValues: undefined;
|
|
270
|
+
baseColumn: never;
|
|
271
|
+
identity: undefined;
|
|
272
|
+
generated: undefined;
|
|
273
|
+
}, {}, {}>;
|
|
274
|
+
organizationId: import("drizzle-orm/pg-core").PgColumn<{
|
|
275
|
+
name: "organization_id";
|
|
276
|
+
tableName: "entity_uom";
|
|
277
|
+
dataType: "string";
|
|
278
|
+
columnType: "PgText";
|
|
279
|
+
data: string;
|
|
280
|
+
driverParam: string;
|
|
281
|
+
notNull: true;
|
|
282
|
+
hasDefault: false;
|
|
283
|
+
isPrimaryKey: false;
|
|
284
|
+
isAutoincrement: false;
|
|
285
|
+
hasRuntimeDefault: false;
|
|
286
|
+
enumValues: [string, ...string[]];
|
|
287
|
+
baseColumn: never;
|
|
288
|
+
identity: undefined;
|
|
289
|
+
generated: undefined;
|
|
290
|
+
}, {}, {}>;
|
|
291
|
+
entityId: import("drizzle-orm/pg-core").PgColumn<{
|
|
292
|
+
name: "entity_id";
|
|
293
|
+
tableName: "entity_uom";
|
|
294
|
+
dataType: "string";
|
|
295
|
+
columnType: "PgUUID";
|
|
296
|
+
data: string;
|
|
297
|
+
driverParam: string;
|
|
298
|
+
notNull: true;
|
|
299
|
+
hasDefault: false;
|
|
300
|
+
isPrimaryKey: false;
|
|
301
|
+
isAutoincrement: false;
|
|
302
|
+
hasRuntimeDefault: false;
|
|
303
|
+
enumValues: undefined;
|
|
304
|
+
baseColumn: never;
|
|
305
|
+
identity: undefined;
|
|
306
|
+
generated: undefined;
|
|
307
|
+
}, {}, {}>;
|
|
308
|
+
purchaseUomId: import("drizzle-orm/pg-core").PgColumn<{
|
|
309
|
+
name: "purchase_uom_id";
|
|
310
|
+
tableName: "entity_uom";
|
|
311
|
+
dataType: "string";
|
|
312
|
+
columnType: "PgUUID";
|
|
313
|
+
data: string;
|
|
314
|
+
driverParam: string;
|
|
315
|
+
notNull: true;
|
|
316
|
+
hasDefault: false;
|
|
317
|
+
isPrimaryKey: false;
|
|
318
|
+
isAutoincrement: false;
|
|
319
|
+
hasRuntimeDefault: false;
|
|
320
|
+
enumValues: undefined;
|
|
321
|
+
baseColumn: never;
|
|
322
|
+
identity: undefined;
|
|
323
|
+
generated: undefined;
|
|
324
|
+
}, {}, {}>;
|
|
325
|
+
stockUomId: import("drizzle-orm/pg-core").PgColumn<{
|
|
326
|
+
name: "stock_uom_id";
|
|
327
|
+
tableName: "entity_uom";
|
|
328
|
+
dataType: "string";
|
|
329
|
+
columnType: "PgUUID";
|
|
330
|
+
data: string;
|
|
331
|
+
driverParam: string;
|
|
332
|
+
notNull: true;
|
|
333
|
+
hasDefault: false;
|
|
334
|
+
isPrimaryKey: false;
|
|
335
|
+
isAutoincrement: false;
|
|
336
|
+
hasRuntimeDefault: false;
|
|
337
|
+
enumValues: undefined;
|
|
338
|
+
baseColumn: never;
|
|
339
|
+
identity: undefined;
|
|
340
|
+
generated: undefined;
|
|
341
|
+
}, {}, {}>;
|
|
342
|
+
saleUomId: import("drizzle-orm/pg-core").PgColumn<{
|
|
343
|
+
name: "sale_uom_id";
|
|
344
|
+
tableName: "entity_uom";
|
|
345
|
+
dataType: "string";
|
|
346
|
+
columnType: "PgUUID";
|
|
347
|
+
data: string;
|
|
348
|
+
driverParam: string;
|
|
349
|
+
notNull: true;
|
|
350
|
+
hasDefault: false;
|
|
351
|
+
isPrimaryKey: false;
|
|
352
|
+
isAutoincrement: false;
|
|
353
|
+
hasRuntimeDefault: false;
|
|
354
|
+
enumValues: undefined;
|
|
355
|
+
baseColumn: never;
|
|
356
|
+
identity: undefined;
|
|
357
|
+
generated: undefined;
|
|
358
|
+
}, {}, {}>;
|
|
359
|
+
yieldPercentage: import("drizzle-orm/pg-core").PgColumn<{
|
|
360
|
+
name: "yield_percentage";
|
|
361
|
+
tableName: "entity_uom";
|
|
362
|
+
dataType: "number";
|
|
363
|
+
columnType: "PgInteger";
|
|
364
|
+
data: number;
|
|
365
|
+
driverParam: string | number;
|
|
366
|
+
notNull: true;
|
|
367
|
+
hasDefault: true;
|
|
368
|
+
isPrimaryKey: false;
|
|
369
|
+
isAutoincrement: false;
|
|
370
|
+
hasRuntimeDefault: false;
|
|
371
|
+
enumValues: undefined;
|
|
372
|
+
baseColumn: never;
|
|
373
|
+
identity: undefined;
|
|
374
|
+
generated: undefined;
|
|
375
|
+
}, {}, {}>;
|
|
376
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
377
|
+
name: "created_at";
|
|
378
|
+
tableName: "entity_uom";
|
|
379
|
+
dataType: "date";
|
|
380
|
+
columnType: "PgTimestamp";
|
|
381
|
+
data: Date;
|
|
382
|
+
driverParam: string;
|
|
383
|
+
notNull: true;
|
|
384
|
+
hasDefault: true;
|
|
385
|
+
isPrimaryKey: false;
|
|
386
|
+
isAutoincrement: false;
|
|
387
|
+
hasRuntimeDefault: false;
|
|
388
|
+
enumValues: undefined;
|
|
389
|
+
baseColumn: never;
|
|
390
|
+
identity: undefined;
|
|
391
|
+
generated: undefined;
|
|
392
|
+
}, {}, {}>;
|
|
393
|
+
updatedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
394
|
+
name: "updated_at";
|
|
395
|
+
tableName: "entity_uom";
|
|
396
|
+
dataType: "date";
|
|
397
|
+
columnType: "PgTimestamp";
|
|
398
|
+
data: Date;
|
|
399
|
+
driverParam: string;
|
|
400
|
+
notNull: true;
|
|
401
|
+
hasDefault: true;
|
|
402
|
+
isPrimaryKey: false;
|
|
403
|
+
isAutoincrement: false;
|
|
404
|
+
hasRuntimeDefault: false;
|
|
405
|
+
enumValues: undefined;
|
|
406
|
+
baseColumn: never;
|
|
407
|
+
identity: undefined;
|
|
408
|
+
generated: undefined;
|
|
409
|
+
}, {}, {}>;
|
|
410
|
+
};
|
|
411
|
+
dialect: "pg";
|
|
412
|
+
}>;
|
|
413
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAYxB,CAAC;AAEJ,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EASxB,CAAC;AAEJ,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAYnB,CAAC"}
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { pgTable, uuid, text, integer, boolean, timestamp, index, uniqueIndex } from "drizzle-orm/pg-core";
|
|
2
|
+
export const unitsOfMeasure = pgTable("units_of_measure", {
|
|
3
|
+
id: uuid("id").defaultRandom().primaryKey(),
|
|
4
|
+
organizationId: text("organization_id").notNull(),
|
|
5
|
+
code: text("code").notNull(),
|
|
6
|
+
name: text("name").notNull(),
|
|
7
|
+
category: text("category", { enum: ["weight", "volume", "length", "count", "area", "time"] }).notNull(),
|
|
8
|
+
isBaseUnit: boolean("is_base_unit").notNull().default(false),
|
|
9
|
+
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
|
|
10
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull(),
|
|
11
|
+
}, (table) => ({
|
|
12
|
+
orgIdx: index("idx_uom_org").on(table.organizationId),
|
|
13
|
+
codeUnique: uniqueIndex("uom_org_code_unique").on(table.organizationId, table.code),
|
|
14
|
+
}));
|
|
15
|
+
export const uomConversions = pgTable("uom_conversions", {
|
|
16
|
+
id: uuid("id").defaultRandom().primaryKey(),
|
|
17
|
+
organizationId: text("organization_id").notNull(),
|
|
18
|
+
fromUnitId: uuid("from_unit_id").references(() => unitsOfMeasure.id, { onDelete: "cascade" }).notNull(),
|
|
19
|
+
toUnitId: uuid("to_unit_id").references(() => unitsOfMeasure.id, { onDelete: "cascade" }).notNull(),
|
|
20
|
+
factor: integer("factor").notNull(),
|
|
21
|
+
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
|
|
22
|
+
}, (table) => ({
|
|
23
|
+
orgIdx: index("idx_uom_conversions_org").on(table.organizationId),
|
|
24
|
+
}));
|
|
25
|
+
export const entityUom = pgTable("entity_uom", {
|
|
26
|
+
id: uuid("id").defaultRandom().primaryKey(),
|
|
27
|
+
organizationId: text("organization_id").notNull(),
|
|
28
|
+
entityId: uuid("entity_id").notNull(),
|
|
29
|
+
purchaseUomId: uuid("purchase_uom_id").references(() => unitsOfMeasure.id).notNull(),
|
|
30
|
+
stockUomId: uuid("stock_uom_id").references(() => unitsOfMeasure.id).notNull(),
|
|
31
|
+
saleUomId: uuid("sale_uom_id").references(() => unitsOfMeasure.id).notNull(),
|
|
32
|
+
yieldPercentage: integer("yield_percentage").notNull().default(100),
|
|
33
|
+
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
|
|
34
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull(),
|
|
35
|
+
}, (table) => ({
|
|
36
|
+
entityUnique: uniqueIndex("entity_uom_org_entity_unique").on(table.organizationId, table.entityId),
|
|
37
|
+
}));
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { PluginResult } from "@unifiedcommerce/core";
|
|
2
|
+
import type { Db, UnitOfMeasure, UOMConversion, EntityUOM, UOMCategory } from "../types";
|
|
3
|
+
export declare class UOMService {
|
|
4
|
+
private db;
|
|
5
|
+
constructor(db: Db);
|
|
6
|
+
createUnit(orgId: string, input: {
|
|
7
|
+
code: string;
|
|
8
|
+
name: string;
|
|
9
|
+
category: UOMCategory;
|
|
10
|
+
isBaseUnit?: boolean;
|
|
11
|
+
}): Promise<PluginResult<UnitOfMeasure>>;
|
|
12
|
+
listUnits(orgId: string, category?: UOMCategory): Promise<PluginResult<UnitOfMeasure[]>>;
|
|
13
|
+
createConversion(orgId: string, input: {
|
|
14
|
+
fromUnitId: string;
|
|
15
|
+
toUnitId: string;
|
|
16
|
+
factor: number;
|
|
17
|
+
}): Promise<PluginResult<UOMConversion>>;
|
|
18
|
+
listConversions(orgId: string): Promise<PluginResult<UOMConversion[]>>;
|
|
19
|
+
convert(orgId: string, input: {
|
|
20
|
+
fromUnitId: string;
|
|
21
|
+
toUnitId: string;
|
|
22
|
+
quantity: number;
|
|
23
|
+
}): Promise<PluginResult<{
|
|
24
|
+
result: number;
|
|
25
|
+
fromCode: string;
|
|
26
|
+
toCode: string;
|
|
27
|
+
}>>;
|
|
28
|
+
setEntityUom(orgId: string, input: {
|
|
29
|
+
entityId: string;
|
|
30
|
+
purchaseUomId: string;
|
|
31
|
+
stockUomId: string;
|
|
32
|
+
saleUomId: string;
|
|
33
|
+
yieldPercentage?: number;
|
|
34
|
+
}): Promise<PluginResult<EntityUOM>>;
|
|
35
|
+
getEntityUom(orgId: string, entityId: string): Promise<PluginResult<EntityUOM>>;
|
|
36
|
+
calculateYield(yieldPercentage: number, requiredQuantity: number): Promise<PluginResult<{
|
|
37
|
+
purchaseQuantity: number;
|
|
38
|
+
}>>;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=uom-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uom-service.d.ts","sourceRoot":"","sources":["../../src/services/uom-service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,KAAK,EAAE,EAAE,EAAE,aAAa,EAAE,aAAa,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEzF,qBAAa,UAAU;IACT,OAAO,CAAC,EAAE;gBAAF,EAAE,EAAE,EAAE;IAEpB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE;QACrC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,WAAW,CAAC;QAAC,UAAU,CAAC,EAAE,OAAO,CAAC;KACzE,GAAG,OAAO,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;IAWlC,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,aAAa,EAAE,CAAC,CAAC;IAOxF,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE;QAC3C,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;KACtD,GAAG,OAAO,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;IASlC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,aAAa,EAAE,CAAC,CAAC;IAMtE,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE;QAClC,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;KACxD,GAAG,OAAO,CAAC,YAAY,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IA+BzE,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE;QACvC,QAAQ,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1G,GAAG,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IAkB9B,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IAO/E,cAAc,CAAC,eAAe,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;QAAE,gBAAgB,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAI7H"}
|