@stamhoofd/models 2.130.0 → 2.132.0
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/factories/OrderFactory.d.ts +27 -0
- package/dist/factories/OrderFactory.d.ts.map +1 -0
- package/dist/factories/OrderFactory.js +51 -0
- package/dist/factories/OrderFactory.js.map +1 -0
- package/dist/factories/TicketFactory.d.ts +20 -0
- package/dist/factories/TicketFactory.d.ts.map +1 -0
- package/dist/factories/TicketFactory.js +35 -0
- package/dist/factories/TicketFactory.js.map +1 -0
- package/dist/factories/index.d.ts +2 -0
- package/dist/factories/index.d.ts.map +1 -1
- package/dist/factories/index.js +2 -0
- package/dist/factories/index.js.map +1 -1
- package/package.json +3 -3
- package/src/factories/OrderFactory.ts +58 -0
- package/src/factories/TicketFactory.ts +41 -0
- package/src/factories/index.ts +2 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Factory } from '@simonbackx/simple-database';
|
|
2
|
+
import { OrderData, OrderStatus } from '@stamhoofd/structures';
|
|
3
|
+
import { Order } from '../models/index.js';
|
|
4
|
+
import type { Webshop } from '../models/index.js';
|
|
5
|
+
declare class Options {
|
|
6
|
+
/** The webshop the order belongs to (provides the organization and numbering). */
|
|
7
|
+
webshop: Webshop;
|
|
8
|
+
firstName?: string;
|
|
9
|
+
lastName?: string;
|
|
10
|
+
email?: string;
|
|
11
|
+
/** Order number. Defaults to the next sequential number of the webshop. */
|
|
12
|
+
number?: number;
|
|
13
|
+
status?: OrderStatus;
|
|
14
|
+
/**
|
|
15
|
+
* Force a specific updatedAt. Stored with a one-second resolution (like the model itself), so
|
|
16
|
+
* milliseconds are zeroed. Applied with a raw update because the model always overwrites
|
|
17
|
+
* updatedAt on save.
|
|
18
|
+
*/
|
|
19
|
+
updatedAt?: Date;
|
|
20
|
+
/** Full OrderData override. Takes precedence over the firstName/lastName/email options. */
|
|
21
|
+
data?: OrderData;
|
|
22
|
+
}
|
|
23
|
+
export declare class OrderFactory extends Factory<Options, Order> {
|
|
24
|
+
create(): Promise<Order>;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=OrderFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OrderFactory.d.ts","sourceRoot":"","sources":["../../src/factories/OrderFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAkB,SAAS,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAG/E,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,cAAM,OAAO;IACT,kFAAkF;IAClF,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2EAA2E;IAC3E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;;;OAIG;IACH,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,2FAA2F;IAC3F,IAAI,CAAC,EAAE,SAAS,CAAC;CACpB;AAED,qBAAa,YAAa,SAAQ,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC;IAC/C,MAAM,IAAI,OAAO,CAAC,KAAK,CAAC;CA8BjC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Database, Factory } from '@simonbackx/simple-database';
|
|
2
|
+
import { Cart, Customer, OrderData, OrderStatus } from '@stamhoofd/structures';
|
|
3
|
+
import { WebshopCounter } from '../helpers/WebshopCounter.js';
|
|
4
|
+
import { Order } from '../models/index.js';
|
|
5
|
+
class Options {
|
|
6
|
+
/** The webshop the order belongs to (provides the organization and numbering). */
|
|
7
|
+
webshop;
|
|
8
|
+
firstName;
|
|
9
|
+
lastName;
|
|
10
|
+
email;
|
|
11
|
+
/** Order number. Defaults to the next sequential number of the webshop. */
|
|
12
|
+
number;
|
|
13
|
+
status;
|
|
14
|
+
/**
|
|
15
|
+
* Force a specific updatedAt. Stored with a one-second resolution (like the model itself), so
|
|
16
|
+
* milliseconds are zeroed. Applied with a raw update because the model always overwrites
|
|
17
|
+
* updatedAt on save.
|
|
18
|
+
*/
|
|
19
|
+
updatedAt;
|
|
20
|
+
/** Full OrderData override. Takes precedence over the firstName/lastName/email options. */
|
|
21
|
+
data;
|
|
22
|
+
}
|
|
23
|
+
export class OrderFactory extends Factory {
|
|
24
|
+
async create() {
|
|
25
|
+
const webshop = this.options.webshop;
|
|
26
|
+
const data = this.options.data ?? OrderData.create({
|
|
27
|
+
customer: Customer.create({
|
|
28
|
+
firstName: this.options.firstName ?? 'John',
|
|
29
|
+
lastName: this.options.lastName ?? 'Doe',
|
|
30
|
+
email: this.options.email ?? 'john.doe@example.com',
|
|
31
|
+
}),
|
|
32
|
+
cart: Cart.create({}),
|
|
33
|
+
});
|
|
34
|
+
const order = new Order();
|
|
35
|
+
order.organizationId = webshop.organizationId;
|
|
36
|
+
order.webshopId = webshop.id;
|
|
37
|
+
order.data = data;
|
|
38
|
+
order.number = this.options.number ?? await WebshopCounter.getNextNumber(webshop);
|
|
39
|
+
order.status = this.options.status ?? OrderStatus.Created;
|
|
40
|
+
order.validAt = new Date();
|
|
41
|
+
await order.save();
|
|
42
|
+
if (this.options.updatedAt) {
|
|
43
|
+
const forced = new Date(this.options.updatedAt);
|
|
44
|
+
forced.setMilliseconds(0);
|
|
45
|
+
await Database.update('UPDATE `webshop_orders` SET `updatedAt` = ? WHERE `id` = ?', [forced, order.id]);
|
|
46
|
+
order.updatedAt = forced;
|
|
47
|
+
}
|
|
48
|
+
return order;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=OrderFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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AC,EAAE,CAAC;QAC7B,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;QAClB,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,MAAM,cAAc,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAClF,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,WAAW,CAAC,OAAO,CAAC;QAC1D,KAAK,CAAC,OAAO,GAAG,IAAI,IAAI,EAAE,CAAC;QAC3B,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;QAEnB,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;YACzB,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YAChD,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;YAC1B,MAAM,QAAQ,CAAC,MAAM,CAAC,4DAA4D,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;YACxG,KAAK,CAAC,SAAS,GAAG,MAAM,CAAC;QAC7B,CAAC;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Factory } from '@simonbackx/simple-database';
|
|
2
|
+
import { Ticket } from '../models/index.js';
|
|
3
|
+
import type { Order } from '../models/index.js';
|
|
4
|
+
declare class Options {
|
|
5
|
+
/** The order the ticket belongs to (provides the organization, webshop and order id). */
|
|
6
|
+
order: Order;
|
|
7
|
+
index?: number;
|
|
8
|
+
total?: number;
|
|
9
|
+
/**
|
|
10
|
+
* Force a specific updatedAt. Stored with a one-second resolution (like the model itself), so
|
|
11
|
+
* milliseconds are zeroed. Applied with a raw update because the model always overwrites
|
|
12
|
+
* updatedAt on save.
|
|
13
|
+
*/
|
|
14
|
+
updatedAt?: Date;
|
|
15
|
+
}
|
|
16
|
+
export declare class TicketFactory extends Factory<Options, Ticket> {
|
|
17
|
+
create(): Promise<Ticket>;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=TicketFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TicketFactory.d.ts","sourceRoot":"","sources":["../../src/factories/TicketFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD,cAAM,OAAO;IACT,yFAAyF;IACzF,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,SAAS,CAAC,EAAE,IAAI,CAAC;CACpB;AAED,qBAAa,aAAc,SAAQ,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC;IACjD,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC;CAqBlC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Database, Factory } from '@simonbackx/simple-database';
|
|
2
|
+
import { Ticket } from '../models/index.js';
|
|
3
|
+
class Options {
|
|
4
|
+
/** The order the ticket belongs to (provides the organization, webshop and order id). */
|
|
5
|
+
order;
|
|
6
|
+
index;
|
|
7
|
+
total;
|
|
8
|
+
/**
|
|
9
|
+
* Force a specific updatedAt. Stored with a one-second resolution (like the model itself), so
|
|
10
|
+
* milliseconds are zeroed. Applied with a raw update because the model always overwrites
|
|
11
|
+
* updatedAt on save.
|
|
12
|
+
*/
|
|
13
|
+
updatedAt;
|
|
14
|
+
}
|
|
15
|
+
export class TicketFactory extends Factory {
|
|
16
|
+
async create() {
|
|
17
|
+
const order = this.options.order;
|
|
18
|
+
const ticket = new Ticket();
|
|
19
|
+
ticket.organizationId = order.organizationId;
|
|
20
|
+
ticket.webshopId = order.webshopId;
|
|
21
|
+
ticket.orderId = order.id;
|
|
22
|
+
ticket.itemId = null;
|
|
23
|
+
ticket.index = this.options.index ?? 1;
|
|
24
|
+
ticket.total = this.options.total ?? 1;
|
|
25
|
+
await ticket.save();
|
|
26
|
+
if (this.options.updatedAt) {
|
|
27
|
+
const forced = new Date(this.options.updatedAt);
|
|
28
|
+
forced.setMilliseconds(0);
|
|
29
|
+
await Database.update('UPDATE `webshop_tickets` SET `updatedAt` = ? WHERE `id` = ?', [forced, ticket.id]);
|
|
30
|
+
ticket.updatedAt = forced;
|
|
31
|
+
}
|
|
32
|
+
return ticket;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=TicketFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TicketFactory.js","sourceRoot":"","sources":["../../src/factories/TicketFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG5C,MAAM,OAAO;IACT,yFAAyF;IACzF,KAAK,CAAQ;IACb,KAAK,CAAU;IACf,KAAK,CAAU;IACf;;;;OAIG;IACH,SAAS,CAAQ;CACpB;AAED,MAAM,OAAO,aAAc,SAAQ,OAAwB;IACvD,KAAK,CAAC,MAAM;QACR,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;QAEjC,MAAM,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;QAC5B,MAAM,CAAC,cAAc,GAAG,KAAK,CAAC,cAAc,CAAC;QAC7C,MAAM,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;QACnC,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC;QACrB,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC;QACvC,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC;QACvC,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAEpB,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;YACzB,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YAChD,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;YAC1B,MAAM,QAAQ,CAAC,MAAM,CAAC,6DAA6D,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;YAC1G,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC;QAC9B,CAAC;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ"}
|
|
@@ -2,7 +2,9 @@ export * from './AddressFactory.js';
|
|
|
2
2
|
export * from './EmergencyContactFactory.js';
|
|
3
3
|
export * from './GroupFactory.js';
|
|
4
4
|
export * from './MemberFactory.js';
|
|
5
|
+
export * from './OrderFactory.js';
|
|
5
6
|
export * from './OrganizationFactory.js';
|
|
7
|
+
export * from './TicketFactory.js';
|
|
6
8
|
export * from './ParentFactory.js';
|
|
7
9
|
export * from './RecordFactory.js';
|
|
8
10
|
export * from './RegisterCodeFactory.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/factories/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACj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;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,oCAAoC,CAAC"}
|
package/dist/factories/index.js
CHANGED
|
@@ -2,7 +2,9 @@ export * from './AddressFactory.js';
|
|
|
2
2
|
export * from './EmergencyContactFactory.js';
|
|
3
3
|
export * from './GroupFactory.js';
|
|
4
4
|
export * from './MemberFactory.js';
|
|
5
|
+
export * from './OrderFactory.js';
|
|
5
6
|
export * from './OrganizationFactory.js';
|
|
7
|
+
export * from './TicketFactory.js';
|
|
6
8
|
export * from './ParentFactory.js';
|
|
7
9
|
export * from './RecordFactory.js';
|
|
8
10
|
export * from './RegisterCodeFactory.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/factories/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4CAA4C,CAAC;AAC3D,cAAc,wCAAwC,CAAC;AACvD,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mBAAmB,CAAC;AAClC,cAAc,mCAAmC,CAAC;AAClD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,oCAAoC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/factories/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4CAA4C,CAAC;AAC3D,cAAc,wCAAwC,CAAC;AACvD,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mBAAmB,CAAC;AAClC,cAAc,mCAAmC,CAAC;AAClD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,oCAAoC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stamhoofd/models",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.132.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@simonbackx/simple-database": "1.37.1",
|
|
45
|
-
"@stamhoofd/test-utils": "2.
|
|
45
|
+
"@stamhoofd/test-utils": "2.132.0",
|
|
46
46
|
"@types/luxon": "3.7.1",
|
|
47
47
|
"@types/uuid": "8.3.4",
|
|
48
48
|
"vitest": "4.1.8"
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"publishConfig": {
|
|
62
62
|
"access": "public"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "f7143688bb7be0cd9f73c209f4b55c9bacdd59b8"
|
|
65
65
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Database, Factory } from '@simonbackx/simple-database';
|
|
2
|
+
import { Cart, Customer, OrderData, OrderStatus } from '@stamhoofd/structures';
|
|
3
|
+
|
|
4
|
+
import { WebshopCounter } from '../helpers/WebshopCounter.js';
|
|
5
|
+
import { Order } from '../models/index.js';
|
|
6
|
+
import type { Webshop } from '../models/index.js';
|
|
7
|
+
|
|
8
|
+
class Options {
|
|
9
|
+
/** The webshop the order belongs to (provides the organization and numbering). */
|
|
10
|
+
webshop: Webshop;
|
|
11
|
+
firstName?: string;
|
|
12
|
+
lastName?: string;
|
|
13
|
+
email?: string;
|
|
14
|
+
/** Order number. Defaults to the next sequential number of the webshop. */
|
|
15
|
+
number?: number;
|
|
16
|
+
status?: OrderStatus;
|
|
17
|
+
/**
|
|
18
|
+
* Force a specific updatedAt. Stored with a one-second resolution (like the model itself), so
|
|
19
|
+
* milliseconds are zeroed. Applied with a raw update because the model always overwrites
|
|
20
|
+
* updatedAt on save.
|
|
21
|
+
*/
|
|
22
|
+
updatedAt?: Date;
|
|
23
|
+
/** Full OrderData override. Takes precedence over the firstName/lastName/email options. */
|
|
24
|
+
data?: OrderData;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class OrderFactory extends Factory<Options, Order> {
|
|
28
|
+
async create(): Promise<Order> {
|
|
29
|
+
const webshop = this.options.webshop;
|
|
30
|
+
|
|
31
|
+
const data = this.options.data ?? OrderData.create({
|
|
32
|
+
customer: Customer.create({
|
|
33
|
+
firstName: this.options.firstName ?? 'John',
|
|
34
|
+
lastName: this.options.lastName ?? 'Doe',
|
|
35
|
+
email: this.options.email ?? 'john.doe@example.com',
|
|
36
|
+
}),
|
|
37
|
+
cart: Cart.create({}),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const order = new Order();
|
|
41
|
+
order.organizationId = webshop.organizationId;
|
|
42
|
+
order.webshopId = webshop.id;
|
|
43
|
+
order.data = data;
|
|
44
|
+
order.number = this.options.number ?? await WebshopCounter.getNextNumber(webshop);
|
|
45
|
+
order.status = this.options.status ?? OrderStatus.Created;
|
|
46
|
+
order.validAt = new Date();
|
|
47
|
+
await order.save();
|
|
48
|
+
|
|
49
|
+
if (this.options.updatedAt) {
|
|
50
|
+
const forced = new Date(this.options.updatedAt);
|
|
51
|
+
forced.setMilliseconds(0);
|
|
52
|
+
await Database.update('UPDATE `webshop_orders` SET `updatedAt` = ? WHERE `id` = ?', [forced, order.id]);
|
|
53
|
+
order.updatedAt = forced;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return order;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Database, Factory } from '@simonbackx/simple-database';
|
|
2
|
+
|
|
3
|
+
import { Ticket } from '../models/index.js';
|
|
4
|
+
import type { Order } from '../models/index.js';
|
|
5
|
+
|
|
6
|
+
class Options {
|
|
7
|
+
/** The order the ticket belongs to (provides the organization, webshop and order id). */
|
|
8
|
+
order: Order;
|
|
9
|
+
index?: number;
|
|
10
|
+
total?: number;
|
|
11
|
+
/**
|
|
12
|
+
* Force a specific updatedAt. Stored with a one-second resolution (like the model itself), so
|
|
13
|
+
* milliseconds are zeroed. Applied with a raw update because the model always overwrites
|
|
14
|
+
* updatedAt on save.
|
|
15
|
+
*/
|
|
16
|
+
updatedAt?: Date;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class TicketFactory extends Factory<Options, Ticket> {
|
|
20
|
+
async create(): Promise<Ticket> {
|
|
21
|
+
const order = this.options.order;
|
|
22
|
+
|
|
23
|
+
const ticket = new Ticket();
|
|
24
|
+
ticket.organizationId = order.organizationId;
|
|
25
|
+
ticket.webshopId = order.webshopId;
|
|
26
|
+
ticket.orderId = order.id;
|
|
27
|
+
ticket.itemId = null;
|
|
28
|
+
ticket.index = this.options.index ?? 1;
|
|
29
|
+
ticket.total = this.options.total ?? 1;
|
|
30
|
+
await ticket.save();
|
|
31
|
+
|
|
32
|
+
if (this.options.updatedAt) {
|
|
33
|
+
const forced = new Date(this.options.updatedAt);
|
|
34
|
+
forced.setMilliseconds(0);
|
|
35
|
+
await Database.update('UPDATE `webshop_tickets` SET `updatedAt` = ? WHERE `id` = ?', [forced, ticket.id]);
|
|
36
|
+
ticket.updatedAt = forced;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return ticket;
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/factories/index.ts
CHANGED
|
@@ -2,7 +2,9 @@ export * from './AddressFactory.js';
|
|
|
2
2
|
export * from './EmergencyContactFactory.js';
|
|
3
3
|
export * from './GroupFactory.js';
|
|
4
4
|
export * from './MemberFactory.js';
|
|
5
|
+
export * from './OrderFactory.js';
|
|
5
6
|
export * from './OrganizationFactory.js';
|
|
7
|
+
export * from './TicketFactory.js';
|
|
6
8
|
export * from './ParentFactory.js';
|
|
7
9
|
export * from './RecordFactory.js';
|
|
8
10
|
export * from './RegisterCodeFactory.js';
|