@unchainedshop/ticketing 2.11.3 → 2.11.4

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.
@@ -0,0 +1,8 @@
1
+ import { TicketingAPI } from './types.js';
2
+ declare const ticketingServices: {
3
+ ticketing: {
4
+ cancelTicketsForProduct: (productId: string, context: TicketingAPI) => Promise<number>;
5
+ };
6
+ };
7
+ export type TicketingServices = typeof ticketingServices;
8
+ export default ticketingServices;
@@ -0,0 +1,20 @@
1
+ const ticketingServices = {
2
+ ticketing: {
3
+ cancelTicketsForProduct: async (productId, context) => {
4
+ const tokensToCancel = await context.modules.warehousing.findTokens({
5
+ productId,
6
+ 'meta.cancelled': null,
7
+ });
8
+ for (const token of tokensToCancel) {
9
+ await context.modules.warehousing.invalidateToken(token._id);
10
+ await context.modules.passes.cancelTicket(token._id);
11
+ }
12
+ await context.modules.products.update(productId, {
13
+ $set: { 'meta.cancelled': true },
14
+ });
15
+ return tokensToCancel.length;
16
+ },
17
+ },
18
+ };
19
+ export default ticketingServices;
20
+ //# sourceMappingURL=services.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"services.js","sourceRoot":"","sources":["../src/services.ts"],"names":[],"mappings":"AAEA,MAAM,iBAAiB,GAAG;IACxB,SAAS,EAAE;QACT,uBAAuB,EAAE,KAAK,EAAE,SAAiB,EAAE,OAAqB,EAAmB,EAAE;YAC3F,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC;gBAClE,SAAS;gBACT,gBAAgB,EAAE,IAAI;aACvB,CAAC,CAAC;YAEH,KAAK,MAAM,KAAK,IAAI,cAAc,EAAE,CAAC;gBACnC,MAAM,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAC7D,MAAM,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACvD,CAAC;YAED,MAAM,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE;gBAC/C,IAAI,EAAE,EAAE,gBAAgB,EAAE,IAAI,EAAE;aACjC,CAAC,CAAC;YAEH,OAAO,cAAc,CAAC,MAAM,CAAC;QAC/B,CAAC;KACF;CACF,CAAC;AAIF,eAAe,iBAAiB,CAAC"}
package/lib/types.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import type { UnchainedCore } from '@unchainedshop/types/core.js';
2
2
  import type { TicketingModule } from './module.js';
3
+ import { TicketingServices } from './services.js';
3
4
  export type TicketingAPI = UnchainedCore & {
4
5
  modules: {
5
6
  passes: TicketingModule;
6
7
  };
8
+ services: TicketingServices;
7
9
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unchainedshop/ticketing",
3
- "version": "2.11.3",
3
+ "version": "2.11.4",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "exports": {
@@ -0,0 +1,27 @@
1
+ import { TicketingAPI } from './types.js';
2
+
3
+ const ticketingServices = {
4
+ ticketing: {
5
+ cancelTicketsForProduct: async (productId: string, context: TicketingAPI): Promise<number> => {
6
+ const tokensToCancel = await context.modules.warehousing.findTokens({
7
+ productId,
8
+ 'meta.cancelled': null,
9
+ });
10
+
11
+ for (const token of tokensToCancel) {
12
+ await context.modules.warehousing.invalidateToken(token._id);
13
+ await context.modules.passes.cancelTicket(token._id);
14
+ }
15
+
16
+ await context.modules.products.update(productId, {
17
+ $set: { 'meta.cancelled': true },
18
+ });
19
+
20
+ return tokensToCancel.length;
21
+ },
22
+ },
23
+ };
24
+
25
+ export type TicketingServices = typeof ticketingServices;
26
+
27
+ export default ticketingServices;
package/src/types.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import type { UnchainedCore } from '@unchainedshop/types/core.js';
2
2
  import type { TicketingModule } from './module.js';
3
+ import { TicketingServices } from './services.js';
3
4
 
4
5
  export type TicketingAPI = UnchainedCore & {
5
6
  modules: { passes: TicketingModule };
7
+ services: TicketingServices;
6
8
  };