sitero 0.0.16 → 0.0.17
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/src/core/server/infrastructure/database/order/command/order-command-repository.js +47 -21
- package/dist/src/web/server/interfaces/actions/resources/order/commands/create/order-create-action.js +3 -2
- package/dist/types/src/core/server/infrastructure/database/order/command/order-command-repository.d.ts +1 -1
- package/dist/types/src/core/server/infrastructure/database/order/command/order-command-repository.d.ts.map +1 -1
- package/dist/types/src/web/server/interfaces/actions/resources/order/commands/create/order-create-action.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/src/core/server/infrastructure/database/order/command/order-command-repository.js
CHANGED
|
@@ -1,35 +1,61 @@
|
|
|
1
1
|
import { connectOne } from '../../utils/connect.js';
|
|
2
2
|
import { orderToDomain } from '../utils/order-to-domain.js';
|
|
3
3
|
|
|
4
|
+
const ORDER_NUMBER_TIME_ZONE = "Asia/Taipei";
|
|
5
|
+
function formatOrderNumberDate(date, timeZone) {
|
|
6
|
+
return new Intl.DateTimeFormat("en-CA", {
|
|
7
|
+
timeZone,
|
|
8
|
+
year: "numeric",
|
|
9
|
+
month: "2-digit",
|
|
10
|
+
day: "2-digit"
|
|
11
|
+
}).format(date).replaceAll("-", "");
|
|
12
|
+
}
|
|
13
|
+
async function generateOrderNumber(tx) {
|
|
14
|
+
const dateKey = formatOrderNumberDate(/* @__PURE__ */ new Date(), ORDER_NUMBER_TIME_ZONE);
|
|
15
|
+
const sequence = await tx.$queryRaw`
|
|
16
|
+
INSERT INTO order_number_sequences ("date", "current_value")
|
|
17
|
+
VALUES (${dateKey}, 1)
|
|
18
|
+
ON CONFLICT ("date")
|
|
19
|
+
DO UPDATE
|
|
20
|
+
SET "current_value" = order_number_sequences."current_value" + 1
|
|
21
|
+
RETURNING "current_value" as "currentValue"
|
|
22
|
+
`;
|
|
23
|
+
return `${dateKey}${String(sequence[0].currentValue).padStart(4, "0")}`;
|
|
24
|
+
}
|
|
4
25
|
function createOrderCommandRepository(prisma) {
|
|
5
26
|
async function create({
|
|
27
|
+
orderNumber: _orderNumber,
|
|
6
28
|
isTest,
|
|
7
29
|
user,
|
|
8
30
|
items,
|
|
9
31
|
...rest
|
|
10
32
|
}) {
|
|
11
|
-
const created = await prisma
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
const created = await prisma.$transaction(async (tx) => {
|
|
34
|
+
const orderNumber = await generateOrderNumber(tx);
|
|
35
|
+
return tx.order.create({
|
|
36
|
+
data: {
|
|
37
|
+
...rest,
|
|
38
|
+
orderNumber,
|
|
39
|
+
// states
|
|
40
|
+
...isTest !== void 0 ? { isTest } : {},
|
|
41
|
+
// ------------------------------------
|
|
42
|
+
// relations
|
|
43
|
+
// ------------------------------------
|
|
44
|
+
// User
|
|
45
|
+
user: connectOne(user),
|
|
46
|
+
// OrderItem
|
|
47
|
+
items: {
|
|
48
|
+
create: items.map(({ product, ...itemRest }) => ({
|
|
49
|
+
...itemRest,
|
|
50
|
+
// ------------------------------------
|
|
51
|
+
// relations
|
|
52
|
+
// ------------------------------------
|
|
53
|
+
// Post
|
|
54
|
+
product: connectOne(product)
|
|
55
|
+
}))
|
|
56
|
+
}
|
|
31
57
|
}
|
|
32
|
-
}
|
|
58
|
+
});
|
|
33
59
|
});
|
|
34
60
|
return orderToDomain(created);
|
|
35
61
|
}
|
|
@@ -2,7 +2,6 @@ import { getTranslator } from 'intor/next/server';
|
|
|
2
2
|
import '../../../../../../../../core/domain/resources/admin/constants.js';
|
|
3
3
|
import '../../../../../../../../core/domain/resources/user/constants.js';
|
|
4
4
|
import { ORDER_SHIPPING_STATUS, ORDER_PAYMENT_STATUS, ORDER_PAYMENT_METHODS } from '../../../../../../../../core/domain/resources/order/props.js';
|
|
5
|
-
import { generateOrderNumber } from '../../../../../../../../core/domain/resources/order/utils/generate-order-number.js';
|
|
6
5
|
import { orderCreateValidator } from './order-create-validator.js';
|
|
7
6
|
|
|
8
7
|
function createOrderCreateAction(ctx) {
|
|
@@ -31,7 +30,9 @@ function createOrderCreateAction(ctx) {
|
|
|
31
30
|
}).parseAsync(formData);
|
|
32
31
|
const order = await repositories.orderCommandRepository.create({
|
|
33
32
|
...rest,
|
|
34
|
-
orderNumber: isTest
|
|
33
|
+
// orderNumber: isTest
|
|
34
|
+
// ? generateOrderNumber({ prefix: "測試" })
|
|
35
|
+
// : generateOrderNumber(),
|
|
35
36
|
// states
|
|
36
37
|
isTest,
|
|
37
38
|
// --- money
|
|
@@ -2,7 +2,7 @@ import type { CreateParams, UpdateParams } from "./types";
|
|
|
2
2
|
import type { PrismaClient } from "../../../../../../../prisma/generated/client";
|
|
3
3
|
import type { Order } from "../../../../../domain";
|
|
4
4
|
export declare function createOrderCommandRepository(prisma: PrismaClient): {
|
|
5
|
-
create: ({ isTest, user, items, ...rest }: CreateParams) => Promise<Order>;
|
|
5
|
+
create: ({ orderNumber: _orderNumber, isTest, user, items, ...rest }: CreateParams) => Promise<Order>;
|
|
6
6
|
update: ({ id, ...rest }: UpdateParams) => Promise<Order>;
|
|
7
7
|
delete: ({ id }: {
|
|
8
8
|
id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order-command-repository.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/core/server/infrastructure/database/order/command/order-command-repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"order-command-repository.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/core/server/infrastructure/database/order/command/order-command-repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,KAAK,EAEV,YAAY,EACb,MAAM,8CAA8C,CAAC;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AA+BnD,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,YAAY;0EAU5D,YAAY,KAAG,OAAO,CAAC,KAAK,CAAC;8BAuCO,YAAY,KAAG,OAAO,CAAC,KAAK,CAAC;qBAarC;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,KAAG,OAAO,CAAC,KAAK,CAAC;EAe/D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order-create-action.d.ts","sourceRoot":"","sources":["../../../../../../../../../../../src/web/server/interfaces/actions/resources/order/commands/create/order-create-action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACf,MAAM,iDAAiD,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,OAAO,
|
|
1
|
+
{"version":3,"file":"order-create-action.d.ts","sourceRoot":"","sources":["../../../../../../../../../../../src/web/server/interfaces/actions/resources/order/commands/create/order-create-action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACf,MAAM,iDAAiD,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,OAAO,EAIL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,QAAQ,EACd,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE;;GAEG;AAEH,MAAM,MAAM,mBAAmB,GAAG,IAAI,CACpC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,EAChD,MAAM,GAAG,WAAW,GAAG,OAAO,GAAG,eAAe,GAAG,gBAAgB,CACpE,GAAG;IACF,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAC;IACtB,SAAS,EAAE,cAAc,GAAG,IAAI,CAAC;IACjC,KAAK,EAAE,UAAU,CAAC;IAClB,aAAa,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACzC,cAAc,EAAE,cAAc,GAAG,IAAI,CAAC;CACvC,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,aAAa,IAUhB,eAErC;IACD,QAAQ,EAAE,mBAAmB,CAAC;CAC/B;;IAqHF"}
|