@arken/node 1.5.1 → 1.5.2

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.
Files changed (148) hide show
  1. package/db.ts +76 -1
  2. package/index.ts +351 -18
  3. package/package.json +3 -3
  4. package/tsconfig.json +33 -2
  5. package/util.ts +1 -0
  6. package/modules/area/area.models.ts +0 -15
  7. package/modules/area/area.router.ts +0 -74
  8. package/modules/area/area.schema.ts +0 -22
  9. package/modules/area/area.service.ts +0 -124
  10. package/modules/area/area.types.ts +0 -26
  11. package/modules/area/index.ts +0 -5
  12. package/modules/asset/asset.models.ts +0 -59
  13. package/modules/asset/asset.router.ts +0 -55
  14. package/modules/asset/asset.schema.ts +0 -27
  15. package/modules/asset/asset.service.ts +0 -85
  16. package/modules/asset/asset.types.ts +0 -22
  17. package/modules/asset/index.ts +0 -5
  18. package/modules/chain/chain.models.ts +0 -50
  19. package/modules/chain/chain.router.ts +0 -104
  20. package/modules/chain/chain.schema.ts +0 -52
  21. package/modules/chain/chain.service.ts +0 -167
  22. package/modules/chain/chain.types.ts +0 -24
  23. package/modules/chain/index.ts +0 -5
  24. package/modules/character/character.models.ts +0 -174
  25. package/modules/character/character.router.ts +0 -314
  26. package/modules/character/character.schema.ts +0 -147
  27. package/modules/character/character.service.ts +0 -876
  28. package/modules/character/character.types.ts +0 -64
  29. package/modules/character/index.ts +0 -5
  30. package/modules/chat/chat.models.ts +0 -43
  31. package/modules/chat/chat.router.ts +0 -67
  32. package/modules/chat/chat.schema.ts +0 -36
  33. package/modules/chat/chat.service.ts +0 -128
  34. package/modules/chat/chat.types.ts +0 -20
  35. package/modules/chat/index.ts +0 -5
  36. package/modules/collection/collection.models.ts +0 -76
  37. package/modules/collection/collection.router.ts +0 -91
  38. package/modules/collection/collection.schema.ts +0 -90
  39. package/modules/collection/collection.service.ts +0 -192
  40. package/modules/collection/collection.types.ts +0 -36
  41. package/modules/collection/index.ts +0 -5
  42. package/modules/core/core.models.ts +0 -1380
  43. package/modules/core/core.router.ts +0 -1781
  44. package/modules/core/core.schema.ts +0 -847
  45. package/modules/core/core.service.ts +0 -2824
  46. package/modules/core/core.types.ts +0 -340
  47. package/modules/core/index.ts +0 -5
  48. package/modules/core/mail/applyPatchesOrMail.ts +0 -568
  49. package/modules/core/mail/mailClaimablePatchesBatch.ts +0 -381
  50. package/modules/game/game.models.ts +0 -53
  51. package/modules/game/game.router.ts +0 -110
  52. package/modules/game/game.schema.ts +0 -23
  53. package/modules/game/game.service.ts +0 -143
  54. package/modules/game/game.types.ts +0 -28
  55. package/modules/game/index.ts +0 -5
  56. package/modules/interface/index.ts +0 -5
  57. package/modules/interface/interface.canonicalize.ts +0 -279
  58. package/modules/interface/interface.models.ts +0 -40
  59. package/modules/interface/interface.router.ts +0 -175
  60. package/modules/interface/interface.schema.ts +0 -59
  61. package/modules/interface/interface.service.ts +0 -356
  62. package/modules/interface/interface.types.ts +0 -25
  63. package/modules/item/index.ts +0 -5
  64. package/modules/item/item.models.ts +0 -124
  65. package/modules/item/item.router.ts +0 -103
  66. package/modules/item/item.schema.ts +0 -120
  67. package/modules/item/item.service.ts +0 -167
  68. package/modules/item/item.types.ts +0 -74
  69. package/modules/job/index.ts +0 -5
  70. package/modules/job/job.models.ts +0 -14
  71. package/modules/job/job.router.ts +0 -44
  72. package/modules/job/job.schema.ts +0 -9
  73. package/modules/job/job.service.ts +0 -243
  74. package/modules/job/job.types.ts +0 -23
  75. package/modules/market/index.ts +0 -5
  76. package/modules/market/market.models.ts +0 -113
  77. package/modules/market/market.router.ts +0 -73
  78. package/modules/market/market.schema.ts +0 -140
  79. package/modules/market/market.service.ts +0 -122
  80. package/modules/market/market.types.ts +0 -56
  81. package/modules/product/index.ts +0 -5
  82. package/modules/product/product.models.ts +0 -166
  83. package/modules/product/product.router.ts +0 -93
  84. package/modules/product/product.schema.ts +0 -149
  85. package/modules/product/product.service.ts +0 -160
  86. package/modules/product/product.types.ts +0 -33
  87. package/modules/profile/index.ts +0 -5
  88. package/modules/profile/profile.models.ts +0 -214
  89. package/modules/profile/profile.router.ts +0 -72
  90. package/modules/profile/profile.schema.ts +0 -156
  91. package/modules/profile/profile.service.ts +0 -149
  92. package/modules/profile/profile.types.ts +0 -22
  93. package/modules/raffle/index.ts +0 -5
  94. package/modules/raffle/raffle.models.ts +0 -44
  95. package/modules/raffle/raffle.router.ts +0 -90
  96. package/modules/raffle/raffle.schema.ts +0 -32
  97. package/modules/raffle/raffle.service.ts +0 -167
  98. package/modules/raffle/raffle.types.ts +0 -30
  99. package/modules/skill/index.ts +0 -5
  100. package/modules/skill/skill.models.ts +0 -16
  101. package/modules/skill/skill.router.ts +0 -201
  102. package/modules/skill/skill.schema.ts +0 -40
  103. package/modules/skill/skill.service.ts +0 -390
  104. package/modules/skill/skill.types.ts +0 -33
  105. package/modules/video/index.ts +0 -5
  106. package/modules/video/video.models.ts +0 -25
  107. package/modules/video/video.router.ts +0 -143
  108. package/modules/video/video.schema.ts +0 -46
  109. package/modules/video/video.service.ts +0 -274
  110. package/modules/video/video.types.ts +0 -33
  111. package/util/db/index.ts +0 -7
  112. package/util/db/isPostgresError.ts +0 -9
  113. package/util/db/isUniqueConstraintViolation.ts +0 -3
  114. package/util/db.ts +0 -62
  115. package/util/index.ts +0 -351
  116. /package/{util/api.ts → api.ts} +0 -0
  117. /package/{util/array.ts → array.ts} +0 -0
  118. /package/{util/browser.ts → browser.ts} +0 -0
  119. /package/{util/codebase.ts → codebase.ts} +0 -0
  120. /package/{util/config.ts → config.ts} +0 -0
  121. /package/{util/decoder.test.ts → decoder.test.ts} +0 -0
  122. /package/{util/decoder.ts → decoder.ts} +0 -0
  123. /package/{util/format.ts → format.ts} +0 -0
  124. /package/{util/guid.ts → guid.ts} +0 -0
  125. /package/{util/json.ts → json.ts} +0 -0
  126. /package/{util/log.ts → log.ts} +0 -0
  127. /package/{util/math.ts → math.ts} +0 -0
  128. /package/{util/merkle.ts → merkle.ts} +0 -0
  129. /package/{util/mongo.ts → mongo.ts} +0 -0
  130. /package/{util/number.ts → number.ts} +0 -0
  131. /package/{util/object.ts → object.ts} +0 -0
  132. /package/{util/otp.ts → otp.ts} +0 -0
  133. /package/{util/physics.ts → physics.ts} +0 -0
  134. /package/{util/process.ts → process.ts} +0 -0
  135. /package/{util/rpc.ts → rpc.ts} +0 -0
  136. /package/{util/seer.ts → seer.ts} +0 -0
  137. /package/{util/string.ts → string.ts} +0 -0
  138. /package/{util/text.ts → text.ts} +0 -0
  139. /package/{util/time → time}/date.ts +0 -0
  140. /package/{util/time → time}/fancyTimeFormat.ts +0 -0
  141. /package/{util/time → time}/index.ts +0 -0
  142. /package/{util/time → time}/now.ts +0 -0
  143. /package/{util/types → types}/mongo.d.ts +0 -0
  144. /package/{util/web3 → web3}/httpProvider.ts +0 -0
  145. /package/{util/web3.ts → web3.ts} +0 -0
  146. /package/{util/websocket.ts → websocket.ts} +0 -0
  147. /package/{util/zk.ts → zk.ts} +0 -0
  148. /package/{util/zod.ts → zod.ts} +0 -0
@@ -1,166 +0,0 @@
1
- import * as mongo from '../../util/mongo';
2
- import type * as Types from './product.types';
3
-
4
- export const Product = mongo.createModel<Types.ProductDocument>(
5
- 'Product',
6
- {
7
- shortDescription: { type: String, maxlength: 300, required: false },
8
- content: { type: String, required: false },
9
- communityId: { type: mongo.Schema.Types.ObjectId, ref: 'Community', required: false },
10
- type: { type: String, default: 'game', maxlength: 100 },
11
- releaseDate: { type: Date },
12
-
13
- // New fields from Objection.js model
14
- parentId: { type: mongo.Schema.Types.ObjectId, ref: 'Product' },
15
- score: { type: Number },
16
- ownerId: { type: mongo.Schema.Types.ObjectId, ref: 'Profile' },
17
- ratingId: { type: mongo.Schema.Types.ObjectId, ref: 'Rating' },
18
- ideaId: { type: mongo.Schema.Types.ObjectId, ref: 'Idea' },
19
- meta: {
20
- name: String,
21
- members: [{ type: mongo.Schema.Types.ObjectId, ref: 'Profile' }],
22
- isProposal: Boolean,
23
- price: Number,
24
- oldPrice: Number,
25
- images: Object,
26
- video: String,
27
- genre: String,
28
- releaseDate: String,
29
- developer: String,
30
- publisher: String,
31
- developerTags: [String],
32
- languageSupport: [Object], // Adjust as needed
33
- systemRequirements: [Object], // Adjust as needed
34
- tags: [{ type: mongo.Schema.Types.ObjectId, ref: 'Tag' }],
35
- type: String,
36
- downloads: Number,
37
- plans: [Object], // Adjust as needed
38
- frequentlyTradedAssets: [{ type: mongo.Schema.Types.ObjectId, ref: 'Asset' }],
39
- saleBox: Object,
40
- assets: [{ type: mongo.Schema.Types.ObjectId, ref: 'Asset' }],
41
- community: Object,
42
- nameUrl: String,
43
- steamId: Number,
44
- author: String,
45
- },
46
- },
47
- {
48
- virtuals: [
49
- {
50
- name: 'projects',
51
- ref: 'Project',
52
- localField: '_id',
53
- foreignField: 'productId',
54
- },
55
- {
56
- name: 'leaderboards',
57
- ref: 'Leaderboard',
58
- localField: '_id',
59
- foreignField: 'productId',
60
- },
61
- {
62
- name: 'games',
63
- ref: 'Game',
64
- localField: '_id',
65
- foreignField: 'productId',
66
- },
67
- {
68
- name: 'productUpdates',
69
- ref: 'ProductUpdate',
70
- localField: '_id',
71
- foreignField: 'productId',
72
- },
73
- // Adding missing relations as virtuals
74
- {
75
- name: 'owner',
76
- ref: 'Profile',
77
- localField: 'ownerId',
78
- foreignField: '_id',
79
- justOne: true,
80
- },
81
- {
82
- name: 'rating',
83
- ref: 'Rating',
84
- localField: 'ratingId',
85
- foreignField: '_id',
86
- justOne: true,
87
- },
88
- {
89
- name: 'community',
90
- ref: 'Community',
91
- localField: 'communityId',
92
- foreignField: '_id',
93
- justOne: true,
94
- },
95
- {
96
- name: 'idea',
97
- ref: 'Idea',
98
- localField: 'ideaId',
99
- foreignField: '_id',
100
- justOne: true,
101
- },
102
- {
103
- name: 'subproducts',
104
- ref: 'Product',
105
- localField: '_id',
106
- foreignField: 'parentId',
107
- },
108
- {
109
- name: 'servers',
110
- ref: 'Server',
111
- localField: '_id',
112
- foreignField: 'productId',
113
- },
114
- // {
115
- // name: 'votes',
116
- // ref: 'Vote',
117
- // localField: '_id',
118
- // foreignField: 'productId',
119
- // through: {
120
- // from: 'nodes.toProductId',
121
- // to: 'nodes.fromVoteId',
122
- // extra: ['relationKey'],
123
- // },
124
- // },
125
- // {
126
- // name: 'files',
127
- // ref: 'File',
128
- // localField: '_id',
129
- // foreignField: 'productId',
130
- // through: {
131
- // from: 'nodes.fromProductId',
132
- // to: 'nodes.toFileId',
133
- // extra: ['relationKey'],
134
- // },
135
- // },
136
- // {
137
- // name: 'tags',
138
- // ref: 'Tag',
139
- // localField: '_id',
140
- // foreignField: 'productId',
141
- // through: {
142
- // from: 'nodes.fromProductId',
143
- // to: 'nodes.toTagId',
144
- // extra: ['relationKey'],
145
- // },
146
- // },
147
- // {
148
- // name: 'internalTags',
149
- // ref: 'Tag',
150
- // localField: '_id',
151
- // foreignField: 'productId',
152
- // through: {
153
- // from: 'nodes.fromProductId',
154
- // to: 'nodes.toTagId',
155
- // extra: ['relationKey'],
156
- // },
157
- // },
158
- ],
159
- }
160
- );
161
-
162
- export const ProductUpdate = mongo.createModel<Types.ProductUpdateDocument>('ProductUpdate', {
163
- productId: { type: mongo.Schema.Types.ObjectId, ref: 'Product', required: true },
164
- updateContent: { type: String, required: true },
165
- updateDate: { type: Date, required: true },
166
- });
@@ -1,93 +0,0 @@
1
- import { z as zod } from 'zod';
2
- import { initTRPC, inferRouterInputs, inferRouterOutputs } from '@trpc/server';
3
- import { customErrorFormatter, hasRole } from '../../util/rpc';
4
- import type { RouterContext } from '../../types';
5
- import { Product, ProductDLC, ProductBundle, ProductReview } from './product.schema';
6
-
7
- export const z = zod;
8
- export const t = initTRPC.context<RouterContext>().create();
9
- export const router = t.router;
10
- export const procedure = t.procedure;
11
-
12
- export const createRouter = () =>
13
- router({
14
- // Product endpoints
15
- getProduct: procedure
16
- .use(hasRole('guest', t))
17
- .use(customErrorFormatter(t))
18
- .input(z.object({ productId: z.string() }))
19
- .query(({ input, ctx }) => (ctx.app.service.Product.getProduct as any)(input, ctx)),
20
-
21
- createProduct: procedure
22
- .use(hasRole('admin', t))
23
- .use(customErrorFormatter(t))
24
- .input(Product)
25
- .mutation(({ input, ctx }) => (ctx.app.service.Product.createProduct as any)(input, ctx)),
26
-
27
- updateProduct: procedure
28
- .use(hasRole('admin', t))
29
- .use(customErrorFormatter(t))
30
- .input(z.object({ productId: z.string(), data: Product.partial() }))
31
- .mutation(({ input, ctx }) => (ctx.app.service.Product.updateProduct as any)(input, ctx)),
32
-
33
- // ProductDLC endpoints
34
- getProductDLC: procedure
35
- .use(hasRole('guest', t))
36
- .use(customErrorFormatter(t))
37
- .input(z.object({ dlcId: z.string() }))
38
- .query(({ input, ctx }) => (ctx.app.service.Product.getProductDLC as any)(input, ctx)),
39
-
40
- createProductDLC: procedure
41
- .use(hasRole('admin', t))
42
- .use(customErrorFormatter(t))
43
- .input(ProductDLC)
44
- .mutation(({ input, ctx }) => (ctx.app.service.Product.createProductDLC as any)(input, ctx)),
45
-
46
- updateProductDLC: procedure
47
- .use(hasRole('admin', t))
48
- .use(customErrorFormatter(t))
49
- .input(z.object({ dlcId: z.string(), data: ProductDLC.partial() }))
50
- .mutation(({ input, ctx }) => (ctx.app.service.Product.updateProductDLC as any)(input, ctx)),
51
-
52
- // ProductBundle endpoints
53
- getProductBundle: procedure
54
- .use(hasRole('guest', t))
55
- .use(customErrorFormatter(t))
56
- .input(z.object({ bundleId: z.string() }))
57
- .query(({ input, ctx }) => (ctx.app.service.Product.getProductBundle as any)(input, ctx)),
58
-
59
- createProductBundle: procedure
60
- .use(hasRole('admin', t))
61
- .use(customErrorFormatter(t))
62
- .input(ProductBundle)
63
- .mutation(({ input, ctx }) => (ctx.app.service.Product.createProductBundle as any)(input, ctx)),
64
-
65
- updateProductBundle: procedure
66
- .use(hasRole('admin', t))
67
- .use(customErrorFormatter(t))
68
- .input(z.object({ bundleId: z.string(), data: ProductBundle.partial() }))
69
- .mutation(({ input, ctx }) => (ctx.app.service.Product.updateProductBundle as any)(input, ctx)),
70
-
71
- // ProductReview endpoints
72
- getProductReview: procedure
73
- .use(hasRole('guest', t))
74
- .use(customErrorFormatter(t))
75
- .input(z.object({ reviewId: z.string() }))
76
- .query(({ input, ctx }) => (ctx.app.service.Product.getProductReview as any)(input, ctx)),
77
-
78
- createProductReview: procedure
79
- .use(hasRole('admin', t))
80
- .use(customErrorFormatter(t))
81
- .input(ProductReview)
82
- .mutation(({ input, ctx }) => (ctx.app.service.Product.createProductReview as any)(input, ctx)),
83
-
84
- updateProductReview: procedure
85
- .use(hasRole('admin', t))
86
- .use(customErrorFormatter(t))
87
- .input(z.object({ reviewId: z.string(), data: ProductReview.partial() }))
88
- .mutation(({ input, ctx }) => (ctx.app.service.Product.updateProductReview as any)(input, ctx)),
89
- });
90
-
91
- export type Router = ReturnType<typeof createRouter>;
92
- export type RouterInput = inferRouterInputs<Router>;
93
- export type RouterOutput = inferRouterOutputs<Router>;
@@ -1,149 +0,0 @@
1
- import { z, ObjectId, Entity } from '../../schema';
2
-
3
- // Extend the ProductMeta schema
4
- const ProductMeta = z.object({
5
- name: z.string(),
6
- members: z.array(ObjectId), // Array of Profile references
7
- isProposal: z.boolean(),
8
- price: z.number().nonnegative(),
9
- oldPrice: z.number().nonnegative().optional(),
10
- images: z.record(z.string(), z.any()),
11
- video: z.string().url(),
12
- genre: z.string(),
13
- releaseDate: z.string(),
14
- developer: z.string(),
15
- publisher: z.string(),
16
- developerTags: z.array(z.string()),
17
- languageSupport: z.array(z.any()), // Replace with actual Language schema if available
18
- systemRequirements: z.array(z.any()), // Replace with actual SystemRequirement schema if available
19
- tags: z.array(ObjectId), // Array of Tag references
20
- type: z.string(),
21
- downloads: z.number().int().nonnegative(),
22
- plans: z.array(z.any()), // Replace with actual ProductPlan schema if available
23
- frequentlyTradedAssets: z.array(ObjectId), // Array of Asset references
24
- saleBox: z.record(z.string(), z.any()),
25
- assets: z.array(ObjectId), // Array of Asset references
26
- community: z.record(z.string(), z.any()),
27
- nameUrl: z.string(),
28
- steamId: z.number().int(),
29
- author: z.string(),
30
- });
31
-
32
- // Updated Product schema
33
- export const Product = Entity.merge(
34
- z.object({
35
- shortDescription: z.string().max(300).min(1),
36
- content: z.string().min(1),
37
- communityId: ObjectId,
38
- type: z.string().max(100).default('game'),
39
- releaseDate: z.date().optional(),
40
- sku: z.string().min(1),
41
- categoryId: ObjectId.optional(),
42
- price: z.number().nonnegative(),
43
- discountPrice: z.number().nonnegative().optional(),
44
- currency: z.string().length(3),
45
- images: z.array(z.string().url()).optional(),
46
- videos: z.array(z.string().url()).optional(),
47
- digitalContent: z
48
- .array(
49
- z.object({
50
- url: z.string().url(),
51
- size: z.number().nonnegative(),
52
- drm: z.enum(['None', 'Steam', 'Epic', 'Uplay', 'Origin']).optional(),
53
- })
54
- )
55
- .optional(),
56
- dlcs: z.array(ObjectId).optional(),
57
- bundles: z.array(ObjectId).optional(),
58
- achievements: z
59
- .array(
60
- z.object({
61
- name: z.string(),
62
- description: z.string().optional(),
63
- icon: z.string().url().optional(),
64
- })
65
- )
66
- .optional(),
67
- reviews: z
68
- .array(
69
- z.object({
70
- userId: ObjectId,
71
- rating: z.number().min(1).max(5),
72
- comment: z.string().optional(),
73
- createdDate: z.date().default(() => new Date()),
74
- })
75
- )
76
- .optional(),
77
- cloudSave: z.boolean().default(false),
78
- ugcSupport: z.boolean().default(false),
79
- wishlistCount: z.number().int().nonnegative().default(0),
80
-
81
- // Additional fields from Objection.js model
82
- parentId: ObjectId.optional(),
83
- score: z.number().optional(),
84
- ownerId: ObjectId.optional(),
85
- ratingId: ObjectId.optional(),
86
- ideaId: ObjectId.optional(),
87
- meta: ProductMeta.optional(),
88
- })
89
- );
90
-
91
- // ProductDLC schema
92
- export const ProductDLC = Entity.merge(
93
- z.object({
94
- name: z.string().min(1),
95
- description: z.string().optional(),
96
- gameId: ObjectId,
97
- price: z.number().nonnegative(),
98
- discountPrice: z.number().nonnegative().optional(),
99
- currency: z.string().length(3),
100
- digitalContent: z
101
- .array(
102
- z.object({
103
- url: z.string().url(),
104
- size: z.number().nonnegative(),
105
- drm: z.enum(['None', 'Steam', 'Epic', 'Uplay', 'Origin']).optional(),
106
- })
107
- )
108
- .optional(),
109
- achievements: z
110
- .array(
111
- z.object({
112
- name: z.string(),
113
- description: z.string().optional(),
114
- icon: z.string().url().optional(),
115
- })
116
- )
117
- .optional(),
118
- })
119
- );
120
-
121
- // ProductBundle schema
122
- export const ProductBundle = Entity.merge(
123
- z.object({
124
- name: z.string().min(1),
125
- description: z.string().optional(),
126
- products: z.array(ObjectId),
127
- price: z.number().nonnegative(),
128
- discountPrice: z.number().nonnegative().optional(),
129
- currency: z.string().length(3),
130
- })
131
- );
132
-
133
- // ProductReview schema
134
- export const ProductReview = Entity.merge(
135
- z.object({
136
- userId: ObjectId,
137
- productId: ObjectId,
138
- rating: z.number().min(1).max(5),
139
- comment: z.string().optional(),
140
- })
141
- );
142
-
143
- export const ProductUpdate = Entity.merge(
144
- z.object({
145
- productId: ObjectId,
146
- updateContent: z.string().min(1),
147
- updateDate: z.date(),
148
- })
149
- );
@@ -1,160 +0,0 @@
1
- import type {
2
- Product,
3
- ProductDLC,
4
- ProductBundle,
5
- ProductReview,
6
- RouterContext,
7
- Router,
8
- RouterInput,
9
- RouterOutput,
10
- } from './product.types';
11
-
12
- export class Service {
13
- async getProduct(input: RouterInput['getProduct'], ctx: RouterContext): Promise<RouterOutput['getProduct']> {
14
- if (!input) throw new Error('Input should not be void');
15
- console.log('Product.Service.getProduct', input.productId);
16
-
17
- const product = await ctx.app.model.Product.findById(input.productId).lean().exec();
18
- if (!product) throw new Error('Product not found');
19
-
20
- return product as Product;
21
- }
22
-
23
- async createProduct(input: RouterInput['createProduct'], ctx: RouterContext): Promise<RouterOutput['createProduct']> {
24
- if (!input) throw new Error('Input should not be void');
25
- console.log('Product.Service.createProduct', input);
26
-
27
- const product = await ctx.app.model.Product.create(input);
28
- return product as Product;
29
- }
30
-
31
- async updateProduct(input: RouterInput['updateProduct'], ctx: RouterContext): Promise<RouterOutput['updateProduct']> {
32
- if (!input) throw new Error('Input should not be void');
33
- console.log('Product.Service.updateProduct', input.productId, input.data);
34
-
35
- const updatedProduct = await ctx.app.model.Product.findByIdAndUpdate(input.productId, input.data, { new: true })
36
- .lean()
37
- .exec();
38
- if (!updatedProduct) throw new Error('Product update failed');
39
-
40
- return updatedProduct as Product;
41
- }
42
-
43
- async getProductDLC(input: RouterInput['getProductDLC'], ctx: RouterContext): Promise<RouterOutput['getProductDLC']> {
44
- if (!input) throw new Error('Input should not be void');
45
- console.log('Product.Service.getProductDLC', input.dlcId);
46
-
47
- const productDLC = await ctx.app.model.ProductDLC.findById(input.dlcId).lean().exec();
48
- if (!productDLC) throw new Error('ProductDLC not found');
49
-
50
- return productDLC as ProductDLC;
51
- }
52
-
53
- async createProductDLC(
54
- input: RouterInput['createProductDLC'],
55
- ctx: RouterContext
56
- ): Promise<RouterOutput['createProductDLC']> {
57
- if (!input) throw new Error('Input should not be void');
58
- console.log('Product.Service.createProductDLC', input);
59
-
60
- const productDLC = await ctx.app.model.ProductDLC.create(input);
61
- return productDLC as ProductDLC;
62
- }
63
-
64
- async updateProductDLC(
65
- input: RouterInput['updateProductDLC'],
66
- ctx: RouterContext
67
- ): Promise<RouterOutput['updateProductDLC']> {
68
- if (!input) throw new Error('Input should not be void');
69
- console.log('Product.Service.updateProductDLC', input.dlcId, input.data);
70
-
71
- const updatedProductDLC = await ctx.app.model.ProductDLC.findByIdAndUpdate(input.dlcId, input.data, { new: true })
72
- .lean()
73
- .exec();
74
- if (!updatedProductDLC) throw new Error('ProductDLC update failed');
75
-
76
- return updatedProductDLC as ProductDLC;
77
- }
78
-
79
- async getProductBundle(
80
- input: RouterInput['getProductBundle'],
81
- ctx: RouterContext
82
- ): Promise<RouterOutput['getProductBundle']> {
83
- if (!input) throw new Error('Input should not be void');
84
- console.log('Product.Service.getProductBundle', input.bundleId);
85
-
86
- const productBundle = await ctx.app.model.ProductBundle.findById(input.bundleId).lean().exec();
87
- if (!productBundle) throw new Error('ProductBundle not found');
88
-
89
- return productBundle as ProductBundle;
90
- }
91
-
92
- async createProductBundle(
93
- input: RouterInput['createProductBundle'],
94
- ctx: RouterContext
95
- ): Promise<RouterOutput['createProductBundle']> {
96
- if (!input) throw new Error('Input should not be void');
97
- console.log('Product.Service.createProductBundle', input);
98
-
99
- const productBundle = await ctx.app.model.ProductBundle.create(input);
100
- return productBundle as ProductBundle;
101
- }
102
-
103
- async updateProductBundle(
104
- input: RouterInput['updateProductBundle'],
105
- ctx: RouterContext
106
- ): Promise<RouterOutput['updateProductBundle']> {
107
- if (!input) throw new Error('Input should not be void');
108
- console.log('Product.Service.updateProductBundle', input.bundleId, input.data);
109
-
110
- const updatedProductBundle = await ctx.app.model.ProductBundle.findByIdAndUpdate(input.bundleId, input.data, {
111
- new: true,
112
- })
113
- .lean()
114
- .exec();
115
- if (!updatedProductBundle) throw new Error('ProductBundle update failed');
116
-
117
- return updatedProductBundle as ProductBundle;
118
- }
119
-
120
- async getProductReview(
121
- input: RouterInput['getProductReview'],
122
- ctx: RouterContext
123
- ): Promise<RouterOutput['getProductReview']> {
124
- if (!input) throw new Error('Input should not be void');
125
- console.log('Product.Service.getProductReview', input.reviewId);
126
-
127
- const productReview = await ctx.app.model.ProductReview.findById(input.reviewId).lean().exec();
128
- if (!productReview) throw new Error('ProductReview not found');
129
-
130
- return productReview as ProductReview;
131
- }
132
-
133
- async createProductReview(
134
- input: RouterInput['createProductReview'],
135
- ctx: RouterContext
136
- ): Promise<RouterOutput['createProductReview']> {
137
- if (!input) throw new Error('Input should not be void');
138
- console.log('Product.Service.createProductReview', input);
139
-
140
- const productReview = await ctx.app.model.ProductReview.create(input);
141
- return productReview as ProductReview;
142
- }
143
-
144
- async updateProductReview(
145
- input: RouterInput['updateProductReview'],
146
- ctx: RouterContext
147
- ): Promise<RouterOutput['updateProductReview']> {
148
- if (!input) throw new Error('Input should not be void');
149
- console.log('Product.Service.updateProductReview', input.reviewId, input.data);
150
-
151
- const updatedProductReview = await ctx.app.model.ProductReview.findByIdAndUpdate(input.reviewId, input.data, {
152
- new: true,
153
- })
154
- .lean()
155
- .exec();
156
- if (!updatedProductReview) throw new Error('ProductReview update failed');
157
-
158
- return updatedProductReview as ProductReview;
159
- }
160
- }
@@ -1,33 +0,0 @@
1
- import { z } from 'zod';
2
- import * as schema from './product.schema';
3
- import { Document, Model } from '../../util/mongo';
4
- import type { RouterContext } from '../../types';
5
- import type { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
6
- import type { Router } from './product.router';
7
-
8
- export type * from './product.router';
9
- export type * from './product.service';
10
- export type { RouterContext };
11
-
12
- export type Product = z.infer<typeof schema.Product>;
13
- export type ProductUpdate = z.infer<typeof schema.ProductUpdate>;
14
- export type ProductDLC = z.infer<typeof schema.ProductDLC>;
15
- export type ProductBundle = z.infer<typeof schema.ProductBundle>;
16
- export type ProductReview = z.infer<typeof schema.ProductReview>;
17
-
18
- export type ProductDocument = Product & Document;
19
- export type ProductUpdateDocument = ProductUpdate & Document;
20
- export type ProductDLCDocument = ProductDLC & Document;
21
- export type ProductBundleDocument = ProductBundle & Document;
22
- export type ProductReviewDocument = ProductReview & Document;
23
-
24
- export type Mappings = {
25
- Product: Model<ProductDocument>;
26
- ProductUpdate: Model<ProductUpdateDocument>;
27
- ProductDLC: Model<ProductDLCDocument>;
28
- ProductBundle: Model<ProductBundleDocument>;
29
- ProductReview: Model<ProductReviewDocument>;
30
- };
31
-
32
- export type RouterInput = inferRouterInputs<Router>;
33
- export type RouterOutput = inferRouterOutputs<Router>;
@@ -1,5 +0,0 @@
1
- export * as Types from './profile.types';
2
- export * as Models from './profile.models';
3
- export * as Schemas from './profile.schema';
4
- export * from './profile.router';
5
- export * from './profile.service';