@arken/node 1.5.0 → 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 (160) hide show
  1. package/build/modules/character/character.service.js.map +1 -1
  2. package/build/modules/chat/chat.service.js.map +1 -1
  3. package/build/modules/core/core.models.js.map +1 -1
  4. package/build/modules/core/core.service.js.map +1 -1
  5. package/build/modules/profile/profile.service.js.map +1 -1
  6. package/build/package.json +2 -2
  7. package/build/tsconfig.tsbuildinfo +1 -1
  8. package/build/types.d.ts +1 -0
  9. package/build/types.js +1 -0
  10. package/build/types.js.map +1 -1
  11. package/build/util/mongo.js.map +1 -1
  12. package/db.ts +76 -1
  13. package/index.ts +351 -18
  14. package/{util/mongo.ts → mongo.ts} +2 -0
  15. package/package.json +3 -3
  16. package/tsconfig.json +33 -2
  17. package/types.ts +2 -0
  18. package/util.ts +1 -0
  19. package/modules/area/area.models.ts +0 -15
  20. package/modules/area/area.router.ts +0 -74
  21. package/modules/area/area.schema.ts +0 -22
  22. package/modules/area/area.service.ts +0 -124
  23. package/modules/area/area.types.ts +0 -26
  24. package/modules/area/index.ts +0 -5
  25. package/modules/asset/asset.models.ts +0 -59
  26. package/modules/asset/asset.router.ts +0 -55
  27. package/modules/asset/asset.schema.ts +0 -27
  28. package/modules/asset/asset.service.ts +0 -85
  29. package/modules/asset/asset.types.ts +0 -22
  30. package/modules/asset/index.ts +0 -5
  31. package/modules/chain/chain.models.ts +0 -50
  32. package/modules/chain/chain.router.ts +0 -104
  33. package/modules/chain/chain.schema.ts +0 -52
  34. package/modules/chain/chain.service.ts +0 -167
  35. package/modules/chain/chain.types.ts +0 -24
  36. package/modules/chain/index.ts +0 -5
  37. package/modules/character/character.models.ts +0 -174
  38. package/modules/character/character.router.ts +0 -314
  39. package/modules/character/character.schema.ts +0 -147
  40. package/modules/character/character.service.ts +0 -875
  41. package/modules/character/character.types.ts +0 -64
  42. package/modules/character/index.ts +0 -5
  43. package/modules/chat/chat.models.ts +0 -43
  44. package/modules/chat/chat.router.ts +0 -67
  45. package/modules/chat/chat.schema.ts +0 -36
  46. package/modules/chat/chat.service.ts +0 -120
  47. package/modules/chat/chat.types.ts +0 -20
  48. package/modules/chat/index.ts +0 -5
  49. package/modules/collection/collection.models.ts +0 -76
  50. package/modules/collection/collection.router.ts +0 -91
  51. package/modules/collection/collection.schema.ts +0 -90
  52. package/modules/collection/collection.service.ts +0 -192
  53. package/modules/collection/collection.types.ts +0 -36
  54. package/modules/collection/index.ts +0 -5
  55. package/modules/core/core.models.ts +0 -1379
  56. package/modules/core/core.router.ts +0 -1781
  57. package/modules/core/core.schema.ts +0 -847
  58. package/modules/core/core.service.ts +0 -2822
  59. package/modules/core/core.types.ts +0 -340
  60. package/modules/core/index.ts +0 -5
  61. package/modules/core/mail/applyPatchesOrMail.ts +0 -568
  62. package/modules/core/mail/mailClaimablePatchesBatch.ts +0 -381
  63. package/modules/game/game.models.ts +0 -53
  64. package/modules/game/game.router.ts +0 -110
  65. package/modules/game/game.schema.ts +0 -23
  66. package/modules/game/game.service.ts +0 -143
  67. package/modules/game/game.types.ts +0 -28
  68. package/modules/game/index.ts +0 -5
  69. package/modules/interface/index.ts +0 -5
  70. package/modules/interface/interface.canonicalize.ts +0 -279
  71. package/modules/interface/interface.models.ts +0 -40
  72. package/modules/interface/interface.router.ts +0 -175
  73. package/modules/interface/interface.schema.ts +0 -59
  74. package/modules/interface/interface.service.ts +0 -356
  75. package/modules/interface/interface.types.ts +0 -25
  76. package/modules/item/index.ts +0 -5
  77. package/modules/item/item.models.ts +0 -124
  78. package/modules/item/item.router.ts +0 -103
  79. package/modules/item/item.schema.ts +0 -120
  80. package/modules/item/item.service.ts +0 -167
  81. package/modules/item/item.types.ts +0 -74
  82. package/modules/job/index.ts +0 -5
  83. package/modules/job/job.models.ts +0 -14
  84. package/modules/job/job.router.ts +0 -44
  85. package/modules/job/job.schema.ts +0 -9
  86. package/modules/job/job.service.ts +0 -243
  87. package/modules/job/job.types.ts +0 -23
  88. package/modules/market/index.ts +0 -5
  89. package/modules/market/market.models.ts +0 -113
  90. package/modules/market/market.router.ts +0 -73
  91. package/modules/market/market.schema.ts +0 -140
  92. package/modules/market/market.service.ts +0 -122
  93. package/modules/market/market.types.ts +0 -56
  94. package/modules/product/index.ts +0 -5
  95. package/modules/product/product.models.ts +0 -166
  96. package/modules/product/product.router.ts +0 -93
  97. package/modules/product/product.schema.ts +0 -149
  98. package/modules/product/product.service.ts +0 -160
  99. package/modules/product/product.types.ts +0 -33
  100. package/modules/profile/index.ts +0 -5
  101. package/modules/profile/profile.models.ts +0 -214
  102. package/modules/profile/profile.router.ts +0 -72
  103. package/modules/profile/profile.schema.ts +0 -156
  104. package/modules/profile/profile.service.ts +0 -147
  105. package/modules/profile/profile.types.ts +0 -22
  106. package/modules/raffle/index.ts +0 -5
  107. package/modules/raffle/raffle.models.ts +0 -44
  108. package/modules/raffle/raffle.router.ts +0 -90
  109. package/modules/raffle/raffle.schema.ts +0 -32
  110. package/modules/raffle/raffle.service.ts +0 -167
  111. package/modules/raffle/raffle.types.ts +0 -30
  112. package/modules/skill/index.ts +0 -5
  113. package/modules/skill/skill.models.ts +0 -16
  114. package/modules/skill/skill.router.ts +0 -201
  115. package/modules/skill/skill.schema.ts +0 -40
  116. package/modules/skill/skill.service.ts +0 -390
  117. package/modules/skill/skill.types.ts +0 -33
  118. package/modules/video/index.ts +0 -5
  119. package/modules/video/video.models.ts +0 -25
  120. package/modules/video/video.router.ts +0 -143
  121. package/modules/video/video.schema.ts +0 -46
  122. package/modules/video/video.service.ts +0 -274
  123. package/modules/video/video.types.ts +0 -33
  124. package/util/db/index.ts +0 -7
  125. package/util/db/isPostgresError.ts +0 -9
  126. package/util/db/isUniqueConstraintViolation.ts +0 -3
  127. package/util/db.ts +0 -62
  128. package/util/index.ts +0 -351
  129. /package/{util/api.ts → api.ts} +0 -0
  130. /package/{util/array.ts → array.ts} +0 -0
  131. /package/{util/browser.ts → browser.ts} +0 -0
  132. /package/{util/codebase.ts → codebase.ts} +0 -0
  133. /package/{util/config.ts → config.ts} +0 -0
  134. /package/{util/decoder.test.ts → decoder.test.ts} +0 -0
  135. /package/{util/decoder.ts → decoder.ts} +0 -0
  136. /package/{util/format.ts → format.ts} +0 -0
  137. /package/{util/guid.ts → guid.ts} +0 -0
  138. /package/{util/json.ts → json.ts} +0 -0
  139. /package/{util/log.ts → log.ts} +0 -0
  140. /package/{util/math.ts → math.ts} +0 -0
  141. /package/{util/merkle.ts → merkle.ts} +0 -0
  142. /package/{util/number.ts → number.ts} +0 -0
  143. /package/{util/object.ts → object.ts} +0 -0
  144. /package/{util/otp.ts → otp.ts} +0 -0
  145. /package/{util/physics.ts → physics.ts} +0 -0
  146. /package/{util/process.ts → process.ts} +0 -0
  147. /package/{util/rpc.ts → rpc.ts} +0 -0
  148. /package/{util/seer.ts → seer.ts} +0 -0
  149. /package/{util/string.ts → string.ts} +0 -0
  150. /package/{util/text.ts → text.ts} +0 -0
  151. /package/{util/time → time}/date.ts +0 -0
  152. /package/{util/time → time}/fancyTimeFormat.ts +0 -0
  153. /package/{util/time → time}/index.ts +0 -0
  154. /package/{util/time → time}/now.ts +0 -0
  155. /package/{util/types → types}/mongo.d.ts +0 -0
  156. /package/{util/web3 → web3}/httpProvider.ts +0 -0
  157. /package/{util/web3.ts → web3.ts} +0 -0
  158. /package/{util/websocket.ts → websocket.ts} +0 -0
  159. /package/{util/zk.ts → zk.ts} +0 -0
  160. /package/{util/zod.ts → zod.ts} +0 -0
@@ -1,2822 +0,0 @@
1
- // arken/packages/node/modules/core/core.service.ts
2
- //
3
- import md5 from 'js-md5';
4
- import type {
5
- RouterContext,
6
- RouterInput,
7
- RouterOutput,
8
- Account,
9
- Achievement,
10
- Act,
11
- Agent,
12
- Application,
13
- Badge,
14
- BattlePass,
15
- Biome,
16
- BiomeFeature,
17
- Bounty,
18
- Collection,
19
- Comment,
20
- Community,
21
- Company,
22
- Conversation,
23
- ConversationMessage,
24
- Data,
25
- Discussion,
26
- Energy,
27
- Event,
28
- File,
29
- Galaxy,
30
- Guide,
31
- Idea,
32
- Leaderboard,
33
- Log,
34
- Lore,
35
- Memory,
36
- Message,
37
- Metaverse,
38
- NewsArticle,
39
- Npc,
40
- Offer,
41
- Omniverse,
42
- Order,
43
- Payment,
44
- Party,
45
- Permission,
46
- Person,
47
- Planet,
48
- Poll,
49
- Project,
50
- Proposal,
51
- Quest,
52
- Rating,
53
- Realm,
54
- RealmEvent,
55
- RealmShard,
56
- Revision,
57
- Referral,
58
- Review,
59
- Role,
60
- Season,
61
- Session,
62
- SolarSystem,
63
- Star,
64
- Stat,
65
- Stash,
66
- Stock,
67
- Suggestion,
68
- Tag,
69
- Team,
70
- Tournament,
71
- Trade,
72
- Universe,
73
- Validator,
74
- Vote,
75
- WorldEvent,
76
- WorldRecord,
77
- } from './core.types';
78
- import { Profile } from '../profile/profile.types';
79
- import { ARXError } from '../../util/rpc';
80
- import { getFilter } from '../../util/api';
81
- import { log, logError } from '../../util';
82
- import { deepMerge } from '../../util/object';
83
- import { Model } from '../../util/mongo';
84
- import { isValidRequest, getSignedRequest } from '../../util/web3';
85
- import type { EntityPatch } from '../../types';
86
- import { claimMailMessage } from './mail/applyPatchesOrMail';
87
- import { mailClaimablePatchesBatch } from './mail/mailClaimablePatchesBatch'; // adjust path
88
-
89
- export class Service {
90
- /**
91
- * Claim a message's patch-grant payload via your central handler.
92
- */
93
- async claimConversationMessage(
94
- input: RouterInput['claimConversationMessage'],
95
- ctx: RouterContext
96
- ): Promise<RouterOutput['claimConversationMessage']> {
97
- if (!ctx.client?.profile) throw new Error('Unauthorized');
98
-
99
- const profileId = ctx.client.profile.id;
100
- const messageId = String((input as any).messageId);
101
- const characterId = (input as any)?.characterId ? String((input as any).characterId) : null;
102
-
103
- const Conversation = ctx.app.model.Conversation;
104
- const ConversationMessage = ctx.app.model.ConversationMessage;
105
- const Profile = ctx.app.model.Profile;
106
-
107
- // Read message first (for authz + to know conversationId)
108
- const msg = await ctx.app.model.ConversationMessage.findById(messageId).lean().exec();
109
- if (!msg) throw new Error('Message not found');
110
-
111
- // Must belong to a conversation the user is in
112
- const convo = await Conversation.findOne({
113
- _id: msg.conversationId,
114
- $or: [{ profileId }, { 'participants.profileId': profileId }],
115
- })
116
- .lean()
117
- .exec();
118
- if (!convo) throw new Error('Not authorized for this message');
119
-
120
- // Load profile doc for applying profile.meta patches
121
- const profile = await Profile.findById(profileId).populate('characters').exec();
122
- if (!profile) throw new Error('Profile not found');
123
-
124
- // Choose character if needed (claim payload might include character.* patches)
125
- let character: any = null;
126
- const chars = (profile as any).characters || [];
127
- if (characterId) {
128
- character = chars.find((c: any) => String(c._id) === characterId) ?? null;
129
- } else {
130
- character = chars?.[0] ?? null; // keep your current default assumption
131
- }
132
-
133
- // ✅ Central claim implementation from applyPatchesOrMail.ts
134
- await claimMailMessage({
135
- ctx,
136
- profile,
137
- character: character ?? undefined,
138
- messageId,
139
- });
140
-
141
- return { ok: true, messageId } as any;
142
- }
143
-
144
- async distributeSantaChristmasTicket(
145
- input: RouterInput['distributeSantaChristmasTicket'],
146
- ctx: RouterContext
147
- ): Promise<RouterOutput['distributeSantaChristmasTicket']> {
148
- if (!input) throw new ARXError('NO_INPUT');
149
- if (!ctx.client?.roles?.includes('admin')) throw new Error('Not authorized');
150
-
151
- const year = 2025;
152
- const dedupeKey = input?.dedupeKey || `broadcast:santa-christmas-ticket:${year}`;
153
-
154
- // ✅ This matches your saveRound behavior:
155
- // profile.meta.rewards.tokens['christmas' + year] += 1
156
- const patches: EntityPatch[] = [
157
- {
158
- entityType: 'profile.meta',
159
- entityId: 'broadcast', // not used for mail application, but keep consistent
160
- // IMPORTANT: your applyPatchesWithInventoryViaMail expects this flag
161
- // to decide “mail vs immediate”. Broadcast is mail-only.
162
- claimable: true as any,
163
- ops: [{ op: 'inc', key: `rewards.tokens.christmas${year}`, value: 1 }],
164
- } as any,
165
- ];
166
-
167
- const result = await mailClaimablePatchesBatch({
168
- ctx,
169
- streamAllProfiles: true,
170
- kind: 'mail',
171
- conversationKey: 'system',
172
- source: 'core.broadcastSantaChristmasTicket',
173
- title: `Holiday Gift 🎁`,
174
- body: `You received a Santa Christmas Ticket (${year}). Claim it to add it to your account.`,
175
- dedupeKey,
176
- claimablePatches: patches,
177
- payloadUi: {
178
- rewards: [{ type: 'token', id: `christmas${year}`, quantity: 1 }],
179
- },
180
- batchSize: input?.batchSize ?? 1000,
181
- });
182
-
183
- return {
184
- ok: true,
185
- year,
186
- dedupeKey,
187
- ...result,
188
- } as any;
189
- }
190
-
191
- /**
192
- * Starred messages for the logged-in user (across all conversations of a kind).
193
- *
194
- * Assumptions:
195
- * - "starred" lives on ConversationMessage.metadata.starred (boolean)
196
- * (also supports metadata.isStarred as a fallback)
197
- * - Viewer must be a participant (or legacy profileId owner) of the message's conversation.
198
- */
199
- async getConversationMessages(
200
- input: { where: any; limit?: number; skip?: number; cursor?: string },
201
- ctx: RouterContext
202
- ) {
203
- if (!input) throw new ARXError('NO_INPUT');
204
- if (!ctx.client?.profile) throw new Error('Unauthorized');
205
-
206
- const profileId = String(ctx.client.profile.id);
207
-
208
- const baseFilter = getFilter(input); // derived from input.where
209
- const limit = Math.min(200, Number(input.limit ?? 50));
210
- const skip = Math.max(0, Number(input.skip ?? 0));
211
- const cursor = input.cursor ? String(input.cursor) : null;
212
-
213
- const Conversation = ctx.app.model.Conversation;
214
- const ConversationMessage = ctx.app.model.ConversationMessage;
215
-
216
- // Pull any conversationId constraint from the filter (if present)
217
- // Depending on your getFilter(), this might be:
218
- // - a string/ObjectId
219
- // - { $in: [...] }
220
- // - undefined
221
- const requestedConversationId = (baseFilter as any)?.conversationId;
222
-
223
- // If caller is asking for a specific conversation (most common UI path)
224
- // then do a direct authz check and only return that conversation's messages.
225
- if (requestedConversationId && typeof requestedConversationId !== 'object') {
226
- const convo = await Conversation.findOne({
227
- _id: requestedConversationId,
228
- $or: [{ profileId }, { 'participants.profileId': profileId }],
229
- })
230
- .select({ _id: 1 })
231
- .lean()
232
- .exec();
233
-
234
- if (!convo) throw new Error('Not authorized for this conversation');
235
-
236
- const msgFilter: any = {
237
- ...baseFilter,
238
- conversationId: requestedConversationId, // keep exact constraint
239
- };
240
-
241
- if (cursor) msgFilter._id = { $lt: cursor };
242
-
243
- const items = await ctx.app.model.ConversationMessage.findJSON(msgFilter, null, {
244
- sort: { _id: -1 },
245
- skip,
246
- limit,
247
- });
248
-
249
- const total = await ctx.app.model.ConversationMessage.countDocumentsFiltered(msgFilter);
250
-
251
- return {
252
- items,
253
- total,
254
- nextCursor: items.length ? String(items[items.length - 1]._id) : null,
255
- };
256
- }
257
-
258
- // Otherwise: “global” query across all conversations user can access
259
- // (needed for starred tab: where: { isStarred: true })
260
- const convos = await Conversation.find({
261
- $or: [{ profileId }, { 'participants.profileId': profileId }],
262
- })
263
- .select({ _id: 1 })
264
- .lean()
265
- .exec();
266
-
267
- const convoIds = convos.map((c: any) => c._id);
268
- if (!convoIds.length) return { items: [], total: 0, nextCursor: null };
269
-
270
- // Intersect baseFilter’s conversationId (if it’s an $in) with allowed convos.
271
- // If baseFilter.conversationId is something else object-y, we keep it and also constrain with $in.
272
- const msgFilter: any = {
273
- ...baseFilter,
274
- conversationId: { $in: convoIds },
275
- };
276
-
277
- // If baseFilter had conversationId: { $in: [...] }, intersect it with allowed convoIds
278
- if (requestedConversationId && typeof requestedConversationId === 'object' && requestedConversationId.$in) {
279
- const wanted = (requestedConversationId.$in || []).map((x: any) => String(x));
280
- const allowed = convoIds.map((x: any) => String(x));
281
- const intersection = wanted.filter((id: string) => allowed.includes(id));
282
- msgFilter.conversationId = { $in: intersection };
283
- if (!intersection.length) return { items: [], total: 0, nextCursor: null };
284
- }
285
-
286
- if (cursor) msgFilter._id = { $lt: cursor };
287
-
288
- const items = await ctx.app.model.ConversationMessage.findJSON(msgFilter, null, {
289
- sort: { _id: -1 },
290
- skip,
291
- limit,
292
- });
293
-
294
- const total = await ctx.app.model.ConversationMessage.countDocumentsFiltered(msgFilter);
295
-
296
- return {
297
- items,
298
- total,
299
- nextCursor: items.length ? String(items[items.length - 1].id) : null,
300
- };
301
- }
302
-
303
- async setConversationMessageStar(
304
- input: { messageId: string; isStarred: boolean },
305
- ctx: RouterContext
306
- ): Promise<{ ok: true; messageId: string; isStarred: boolean }> {
307
- if (!ctx.client?.profile) throw new Error('Unauthorized');
308
-
309
- const profileId = String(ctx.client.profile.id);
310
- const messageId = String(input.messageId);
311
- const isStarred = !!input.isStarred;
312
-
313
- const Conversation = ctx.app.model.Conversation;
314
- const ConversationMessage = ctx.app.model.ConversationMessage;
315
-
316
- const msg = await ConversationMessage.findById(messageId).lean().exec();
317
- if (!msg) throw new Error('Message not found');
318
-
319
- const convo = await Conversation.findOne({
320
- _id: msg.conversationId,
321
- $or: [{ profileId }, { 'participants.profileId': profileId }],
322
- })
323
- .select({ _id: 1 })
324
- .lean()
325
- .exec();
326
-
327
- if (!convo) throw new Error('Not authorized for this message');
328
-
329
- await ConversationMessage.updateOne({ _id: messageId }, { $set: { isStarred } }).exec();
330
-
331
- return { ok: true, messageId, isStarred };
332
- }
333
-
334
- async distributeSantaChristmasTicketToProfile(
335
- input: { profileId: string; dedupeKey?: string },
336
- ctx: RouterContext
337
- ): Promise<any> {
338
- if (!input?.profileId) throw new ARXError('NO_INPUT');
339
- if (!ctx.client?.roles?.includes('admin')) throw new Error('Not authorized');
340
-
341
- const year = 2025;
342
- const dedupeKey = input?.dedupeKey || `broadcast:santa-christmas-ticket:${year}`;
343
-
344
- const patches: EntityPatch[] = [
345
- {
346
- entityType: 'profile.meta',
347
- entityId: 'broadcast',
348
- claimable: true as any,
349
- ops: [{ op: 'inc', key: `rewards.tokens.christmas${year}`, value: 1 }],
350
- } as any,
351
- ];
352
-
353
- // single-target run: use batch helper with explicit profileIds
354
- const result = await mailClaimablePatchesBatch({
355
- ctx,
356
- profileIds: [input.profileId],
357
- kind: 'mail',
358
- conversationKey: 'system',
359
- source: 'core.broadcastSantaChristmasTicket',
360
- title: `Holiday Gift 🎁`,
361
- body: `You received a Santa Christmas Ticket (${year}). Claim it to add it to your account.`,
362
- dedupeKey,
363
- claimablePatches: patches,
364
- payloadUi: {
365
- rewards: [{ type: 'token', id: `christmas${year}`, quantity: 1 }],
366
- },
367
- batchSize: 1,
368
- });
369
-
370
- return {
371
- ok: true,
372
- year,
373
- dedupeKey,
374
- profileId: input.profileId,
375
- ...result,
376
- } as any;
377
- }
378
- async readAndClaimLatestMail(
379
- input: { conversationId: string; limit?: number; characterId?: string } | undefined,
380
- ctx: RouterContext
381
- ): Promise<{ ok: true; conversationId: string; readCount: number; claimedCount: number }> {
382
- if (!input?.conversationId) throw new ARXError('NO_INPUT');
383
- if (!ctx.client?.profile) throw new Error('Unauthorized');
384
-
385
- const profileId = String(ctx.client.profile.id);
386
- const conversationId = String(input.conversationId);
387
- const limit = Math.max(1, Math.min(200, Number(input.limit ?? 50)));
388
- const characterId = input?.characterId ? String(input.characterId) : null;
389
-
390
- const Conversation = ctx.app.model.Conversation;
391
- const ConversationMessage = ctx.app.model.ConversationMessage;
392
- const Profile = ctx.app.model.Profile;
393
-
394
- const convo = await Conversation.findOne({
395
- _id: conversationId,
396
- $or: [{ profileId }, { 'participants.profileId': profileId }],
397
- })
398
- .lean()
399
- .exec();
400
-
401
- if (!convo) throw new Error('Not authorized');
402
-
403
- // Load latest messages
404
- const msgs = await ConversationMessage.find({
405
- conversationId,
406
- status: { $ne: 'Archived' },
407
- })
408
- .sort({ _id: -1 })
409
- .limit(limit)
410
- .lean()
411
- .exec();
412
-
413
- // Mark as read at conversation participant level
414
- const now = new Date();
415
- await Conversation.updateOne(
416
- { _id: conversationId },
417
- {
418
- $set: {
419
- 'participants.$[p].lastReadDate': now,
420
- 'participants.$[p].unreadCount': 0,
421
- },
422
- },
423
- {
424
- arrayFilters: [
425
- {
426
- 'p.profileId': (ctx.app as any).db?.mongoose?.Types?.ObjectId?.isValid?.(profileId)
427
- ? (ctx.app as any).db.mongoose.Types.ObjectId(profileId)
428
- : profileId,
429
- },
430
- ] as any,
431
- }
432
- )
433
- .exec()
434
- .catch(async () => {
435
- // fallback if arrayFilters / ObjectId mismatch in your wrapper
436
- await Conversation.updateOne(
437
- { _id: conversationId, 'participants.profileId': profileId },
438
- { $set: { 'participants.$.lastReadDate': now, 'participants.$.unreadCount': 0 } }
439
- ).exec();
440
- });
441
-
442
- // Load profile+character once for all claims
443
- const profile = await Profile.findById(profileId).populate('characters').exec();
444
- if (!profile) throw new Error('Profile not found');
445
-
446
- let character: any = null;
447
- const chars = (profile as any).characters || [];
448
- if (characterId) character = chars.find((c: any) => String(c._id) === characterId) ?? null;
449
- else character = chars?.[0] ?? null;
450
-
451
- let claimedCount = 0;
452
-
453
- for (const m of msgs) {
454
- const claimable = !!(m as any)?.claim?.isClaimable && !(m as any)?.claim?.claimedDate;
455
- if (!claimable) continue;
456
-
457
- try {
458
- await claimMailMessage({
459
- ctx,
460
- profile,
461
- character: character ?? undefined,
462
- messageId: String((m as any)._id),
463
- });
464
- claimedCount += 1;
465
- } catch {
466
- // ignore already-claimed / races
467
- }
468
- }
469
-
470
- return { ok: true, conversationId, readCount: msgs.length, claimedCount };
471
- }
472
- async archiveReadConversations(
473
- input: { conversationId: string } | undefined,
474
- ctx: RouterContext
475
- ): Promise<{ ok: true; conversationId: string; archivedCount: number }> {
476
- if (!input?.conversationId) throw new ARXError('NO_INPUT');
477
- if (!ctx.client?.profile) throw new Error('Unauthorized');
478
-
479
- const profileId = String(ctx.client.profile.id);
480
- const conversationId = String(input.conversationId);
481
-
482
- const Conversation = ctx.app.model.Conversation;
483
- const ConversationMessage = ctx.app.model.ConversationMessage;
484
-
485
- const convo = await Conversation.findOne({
486
- _id: conversationId,
487
- $or: [{ profileId }, { 'participants.profileId': profileId }],
488
- })
489
- .lean()
490
- .exec();
491
-
492
- if (!convo) throw new Error('Not authorized');
493
-
494
- const participant = Array.isArray((convo as any).participants)
495
- ? (convo as any).participants.find((p: any) => String(p.profileId) === profileId)
496
- : null;
497
-
498
- const lastReadDate = participant?.lastReadDate ? new Date(participant.lastReadDate) : new Date(0);
499
-
500
- const res = await ConversationMessage.updateMany(
501
- {
502
- conversationId,
503
- status: { $ne: 'Archived' },
504
- isStarred: { $ne: true }, // optional: don't delete starred
505
- createdDate: { $lte: lastReadDate }, // assumes you have createdDate timestamps
506
- },
507
- { $set: { status: 'Archived' } }
508
- ).exec();
509
-
510
- const archivedCount = Number((res as any)?.modifiedCount ?? (res as any)?.nModified ?? 0);
511
-
512
- return { ok: true, conversationId, archivedCount };
513
- }
514
- async markConversationRead(
515
- input:
516
- | {
517
- // explicit IDs (preferred from UI)
518
- messageIds?: string[];
519
- // optional scoping (handy for server-side selection)
520
- conversationId?: string;
521
- // optional convenience: if messageIds omitted, mark latest N in conversation
522
- limit?: number;
523
- }
524
- | undefined,
525
- ctx: RouterContext
526
- ): Promise<{ ok: true; updatedCount: number; messageIds?: string[] }> {
527
- if (!ctx.client?.profile) throw new Error('Unauthorized');
528
-
529
- const profileId = String(ctx.client.profile.id);
530
-
531
- const Conversation = ctx.app.model.Conversation;
532
- const ConversationMessage = ctx.app.model.ConversationMessage;
533
-
534
- const messageIds = Array.isArray((input as any)?.messageIds)
535
- ? (input as any).messageIds.map((x: any) => String(x)).filter(Boolean)
536
- : [];
537
-
538
- const conversationId = (input as any)?.conversationId ? String((input as any).conversationId) : null;
539
- const limit = Math.min(200, Number((input as any)?.limit ?? 50));
540
-
541
- // Build candidate message IDs if caller didn't provide them
542
- let targetIds: string[] = messageIds;
543
-
544
- if (!targetIds.length) {
545
- if (!conversationId) {
546
- // nothing to do
547
- return { ok: true, updatedCount: 0 };
548
- }
549
-
550
- // Ensure user has access to this conversation
551
- const convo = await Conversation.findOne({
552
- _id: conversationId,
553
- $or: [{ profileId }, { 'participants.profileId': profileId }],
554
- })
555
- .lean()
556
- .exec();
557
- if (!convo) throw new Error('Not authorized for this conversation');
558
-
559
- // Pull latest N messages in that conversation
560
- const docs = await ConversationMessage.find({ conversationId })
561
- .sort({ _id: -1 })
562
- .limit(limit)
563
- .select({ _id: 1 })
564
- .lean()
565
- .exec();
566
-
567
- targetIds = docs.map((d: any) => String(d._id));
568
- if (!targetIds.length) return { ok: true, updatedCount: 0 };
569
- } else {
570
- // Authz: ensure messages are in conversations the user can access
571
- const msgs = await ConversationMessage.find({ _id: { $in: targetIds } })
572
- .select({ _id: 1, conversationId: 1 })
573
- .lean()
574
- .exec();
575
-
576
- if (!msgs.length) return { ok: true, updatedCount: 0 };
577
-
578
- const convoIds = Array.from(new Set(msgs.map((m: any) => String(m.conversationId))));
579
- const allowed = await Conversation.find({
580
- _id: { $in: convoIds },
581
- $or: [{ profileId }, { 'participants.profileId': profileId }],
582
- })
583
- .select({ _id: 1 })
584
- .lean()
585
- .exec();
586
-
587
- const allowedSet = new Set(allowed.map((c: any) => String(c._id)));
588
-
589
- // Only mark read for messages in allowed conversations
590
- targetIds = msgs.filter((m: any) => allowedSet.has(String(m.conversationId))).map((m: any) => String(m._id));
591
-
592
- if (!targetIds.length) throw new Error('Not authorized for these messages');
593
- }
594
-
595
- // Update: pick ONE canonical read representation.
596
- // If you already use `status` elsewhere (and archive expects status='Archived'),
597
- // then use status='Read' here.
598
- const res = await ConversationMessage.updateMany(
599
- { _id: { $in: targetIds } },
600
- {
601
- $set: {
602
- status: 'Read',
603
- // optional: keep a timestamp if you want
604
- readDate: new Date(),
605
- },
606
- }
607
- ).exec();
608
-
609
- const updatedCount = Number((res as any)?.modifiedCount ?? (res as any)?.nModified ?? 0);
610
-
611
- return { ok: true, updatedCount, messageIds: targetIds };
612
- }
613
- // Conversation Methods
614
- async getConversations(
615
- input: RouterInput['getConversations'],
616
- ctx: RouterContext
617
- ): Promise<RouterOutput['getConversations']> {
618
- if (!input) throw new ARXError('NO_INPUT');
619
- const filter = getFilter(input);
620
- const limit = input.limit ?? 50;
621
- const skip = input.skip ?? 0;
622
- const [items, total] = await Promise.all([
623
- ctx.app.model.Conversation.findJSON(filter, null, { skip, limit }),
624
- ctx.app.model.Conversation.find(filter).countDocuments().exec(),
625
- ]);
626
- return { items, total };
627
- }
628
- async getConversation(
629
- input: RouterInput['getConversation'],
630
- ctx: RouterContext
631
- ): Promise<RouterOutput['getConversation']> {
632
- if (!input) throw new ARXError('NO_INPUT');
633
- log('Core.Service.getConversation', input);
634
-
635
- const AUTO_CREATE_KEYS = new Set(['system', 'battles', 'reports', 'guild']);
636
-
637
- function titleCase(s: string) {
638
- if (!s) return s;
639
- return s.charAt(0).toUpperCase() + s.slice(1);
640
- }
641
-
642
- function defaultsForKey(key: string) {
643
- // Keep this minimal; anything not provided will fall back to schema defaults.
644
- // Use fields you clearly already have on Conversation (from your logs).
645
- if (key === 'system') {
646
- return {
647
- name: 'System',
648
- category: 'system',
649
- kind: 'mail',
650
- isLocked: true,
651
- allowUserSend: false,
652
- importance: 0,
653
- };
654
- }
655
-
656
- return {
657
- name: titleCase(key), // Reports/Guild/Battles
658
- category: key,
659
- kind: 'mail',
660
- isLocked: false,
661
- allowUserSend: false,
662
- importance: 0,
663
- };
664
- }
665
-
666
- if (!ctx.client?.profile?.id) throw new Error('Unauthorized');
667
-
668
- // Always scope to the caller
669
- input.where = input.where || {};
670
- input.where.profileId = { equals: ctx.client.profile.id };
671
-
672
- const where = input.where || {};
673
- const requestedKey =
674
- typeof where?.key === 'string' ? where.key : typeof where?.key?.equals === 'string' ? where.key.equals : null;
675
-
676
- // 1) Try to fetch existing
677
- let conversation = await ctx.app.model.Conversation.findOneJSON(getFilter(input));
678
- if (conversation) return conversation as any;
679
-
680
- // 2) Auto-create only for the known mailbox keys
681
- if (!requestedKey || !AUTO_CREATE_KEYS.has(requestedKey)) {
682
- throw new Error('Conversation not found');
683
- }
684
-
685
- const profileId = String(ctx.client.profile.id);
686
-
687
- // IMPORTANT:
688
- // Use create/upsert in a way that's safe under races.
689
- // If you have a unique index on (profileId, key, applicationId),
690
- // a duplicate create could happen — so we "create, then refetch" and tolerate dup errors.
691
- const createDoc: any = {
692
- key: requestedKey,
693
- profileId,
694
- ...defaultsForKey(requestedKey),
695
-
696
- // these fields exist in your logged response; seed them so UI behaves immediately
697
- participants: [
698
- {
699
- profileId,
700
- role: 'user',
701
- lastReadAt: new Date(0),
702
- unreadCount: 0,
703
- isMuted: false,
704
- isPinned: false,
705
- isArchived: false,
706
- isDeleted: false,
707
- },
708
- ],
709
-
710
- messages: [],
711
- messageCount: 0,
712
- lastMessageDate: null,
713
- lastMessagePreview: '',
714
- meta: {},
715
- data: {},
716
- status: 'Active',
717
- };
718
-
719
- try {
720
- await ctx.app.model.Conversation.create(createDoc as any);
721
- } catch (err: any) {
722
- // If a race created it first, just refetch.
723
- // If you want to be stricter: check err.code === 11000 for dup key.
724
- log('getConversation auto-create race/err', err?.message || err);
725
- }
726
-
727
- conversation = await ctx.app.model.Conversation.findOneJSON(getFilter(input));
728
- if (!conversation) throw new Error('Conversation not found');
729
- return conversation as any;
730
- }
731
- async createConversation(
732
- input: RouterInput['createConversation'],
733
- ctx: RouterContext
734
- ): Promise<RouterOutput['createConversation']> {
735
- if (!input) throw new ARXError('NO_INPUT');
736
- log('Core.Service.createConversation', input);
737
-
738
- const conversation = await ctx.app.model.Conversation.create(input.data);
739
- return conversation as Conversation;
740
- }
741
- async updateConversation(
742
- input: RouterInput['updateConversation'],
743
- ctx: RouterContext
744
- ): Promise<RouterOutput['updateConversation']> {
745
- if (!input) throw new ARXError('NO_INPUT');
746
-
747
- const filters = getFilter(input);
748
-
749
- if (!filters._id) throw new ARXError('BAD_REQUEST');
750
-
751
- log('Core.Service.updateConversation', input);
752
- const updatedConversation = await ctx.app.model.Conversation.findByIdAndUpdate(filters._id, input.data, {
753
- new: true,
754
- })
755
- .lean()
756
- .exec();
757
- if (!updatedConversation) throw new Error('Conversation update failed');
758
- return updatedConversation as Conversation;
759
- }
760
- // ConversationMessage Methods
761
- async getConversationMessage(
762
- input: RouterInput['getConversationMessage'],
763
- ctx: RouterContext
764
- ): Promise<RouterOutput['getConversationMessage']> {
765
- if (!input) throw new ARXError('NO_INPUT');
766
- log('Core.Service.getConversationMessage', input);
767
- const conversationMessage = await ctx.app.model.ConversationMessage.findOneJSON(getFilter(input));
768
- if (!conversationMessage) throw new Error('ConversationMessage not found');
769
- return conversationMessage as ConversationMessage;
770
- }
771
- async createConversationMessage(
772
- input: RouterInput['createConversationMessage'],
773
- ctx: RouterContext
774
- ): Promise<RouterOutput['createConversationMessage']> {
775
- if (!input) throw new ARXError('NO_INPUT');
776
- log('Core.Service.createConversationMessage', input);
777
- const conversationMessage = await ctx.app.model.ConversationMessage.create(input.data);
778
- return conversationMessage as ConversationMessage;
779
- }
780
- async updateConversationMessage(
781
- input: RouterInput['updateConversationMessage'],
782
- ctx: RouterContext
783
- ): Promise<RouterOutput['updateConversationMessage']> {
784
- if (!input) throw new ARXError('NO_INPUT');
785
- log('Core.Service.updateConversationMessage', input);
786
- const updatedConversationMessage = await ctx.app.model.ConversationMessage.findByIdAndUpdate(
787
- input.where.id.equals,
788
- input.data,
789
- { new: true }
790
- )
791
- .lean()
792
- .exec();
793
- if (!updatedConversationMessage) throw new Error('ConversationMessage update failed');
794
- return updatedConversationMessage as ConversationMessage;
795
- }
796
- // async deleteConversation(
797
- // input: RouterInput['deleteConversation'],
798
- // ctx: RouterContext
799
- // ): Promise<RouterOutput['deleteConversation']> {
800
- // if (!input) throw new ARXError('NO_INPUT');
801
- // log('Core.Service.deleteConversation', input);
802
- // const deleted = await ctx.app.model.Conversation.findByIdAndDelete(input.where.id.equals).exec();
803
- // if (!deleted) throw new Error('Conversation not found');
804
- // return { id: input.where.id.equals };
805
- // }
806
- // async interact(input: RouterInput['interact'], ctx: RouterContext): Promise<RouterOutput['interact']> {
807
- // if (!input) throw new TRPCError({
808
- // code: 'BAD_REQUEST',
809
- // message: 'No input provided',
810
- // });
811
- // log('Core.Service.interact', input);
812
- // return {
813
- // status: 1,
814
- // };
815
- // }
816
- async updateSettings(
817
- input: RouterInput['updateSettings'],
818
- ctx: RouterContext
819
- ): Promise<RouterOutput['updateSettings']> {
820
- if (!ctx.client.profile) return;
821
- type ProfileSettings = NonNullable<Profile['settings']>;
822
- // 👇 These must be real keys of ProfileSettings or TS will error
823
- const validKeys = ['warp', 'designer'] as const satisfies readonly (keyof ProfileSettings)[];
824
- type ValidKey = (typeof validKeys)[number];
825
- const incoming = input as Record<string, any>;
826
- for (const key of Object.keys(incoming) as ValidKey[]) {
827
- if (!validKeys.includes(key)) continue;
828
- const prev = ctx.client.profile.settings[key] || {};
829
- ctx.client.profile.settings[key] = deepMerge(prev, incoming[key]);
830
- }
831
- // If settings is Mixed/Map, make sure Mongoose knows it changed:
832
- // @ts-ignore
833
- ctx.client.profile.markModified('settings');
834
- // @ts-ignore
835
- await ctx.client.profile.save(); // writes to DB and keeps this doc in sync
836
- return ctx.client.profile.settings as RouterOutput['updateSettings'];
837
- } // Core.Service.ts (or wherever this class lives)
838
-
839
- async ask(input: RouterInput['ask'], ctx: RouterContext): Promise<RouterOutput['ask']> {
840
- if (!input) throw new ARXError('NO_INPUT');
841
- log('Core.Service.ask', input);
842
-
843
- // Expecting: { conversationId, messages: [{ role, content, ... }, ...], ... }
844
- const { conversationId, messages } = input.data;
845
-
846
- if (!conversationId) {
847
- throw new Error('NO_CONVERSATION_ID');
848
- }
849
-
850
- if (!Array.isArray(messages) || messages.length === 0) {
851
- throw new Error('NO_MESSAGES');
852
- }
853
-
854
- // Take the last message as the "new" user message
855
- const lastMessage = messages[messages.length - 1];
856
- if (!lastMessage?.content) {
857
- throw new Error('NO_MESSAGE_CONTENT');
858
- }
859
-
860
- const userRole = lastMessage.role || 'user';
861
-
862
- // 1) Persist the user message
863
- await ctx.app.model.ConversationMessage.create({
864
- conversationId,
865
- role: userRole,
866
- content: lastMessage.content,
867
- });
868
-
869
- // 2) Call your real LLM / agent here (for now it's a stub)
870
- // You can replace this block with your actual LLM call later.
871
- const assistantReply: RouterOutput['ask'] = {
872
- content: 'Request success.',
873
- role: 'assistant',
874
- };
875
-
876
- // 3) Persist the assistant reply
877
- await ctx.app.model.ConversationMessage.create({
878
- conversationId,
879
- role: assistantReply.role,
880
- content: assistantReply.content,
881
- });
882
-
883
- // 4) Return reply for streaming / UI
884
- return assistantReply;
885
- }
886
-
887
- // Account Methods
888
- async authorize(input: RouterInput['authorize'], ctx: RouterContext): Promise<RouterOutput['authorize']> {
889
- if (!input) throw new ARXError('NO_INPUT');
890
- log('Core.Service.authorize', input);
891
- // Validate token
892
- const isValid = await isValidRequest(ctx.app.web3.bsc, {
893
- signature: {
894
- address: input.address,
895
- hash: input.token,
896
- data: input.data || 'evolution',
897
- },
898
- });
899
-
900
- if (!isValid) throw new Error(`Invalid signature: ${input.address} ${input.token}`);
901
-
902
- ctx.client.profile = await ctx.app.model.Profile.findOne({
903
- address: input.address,
904
- });
905
-
906
- if (!ctx.client.profile) throw new Error('Profile not found: ' + input.address);
907
-
908
- const roles = ['guest'];
909
-
910
- if (
911
- input.address.toLowerCase() === '0xDfA8f768d82D719DC68E12B199090bDc3691fFc7'.toLowerCase() || // realm
912
- input.address.toLowerCase() === '0x81F8C054667046171C0EAdC73063Da557a828d6f'.toLowerCase() || // seer
913
- input.address.toLowerCase() === '0x954246b18fee13712C48E5a7Da5b78D88e8891d5'.toLowerCase() // admin
914
- ) {
915
- roles.push('mod');
916
- roles.push('admin');
917
- }
918
-
919
- roles.push('user');
920
-
921
- ctx.client.roles = roles;
922
-
923
- const permissions = {
924
- 'character.create': roles.includes('mod'),
925
- 'character.view': roles.includes('mod'),
926
- 'character.remove': roles.includes('mod'),
927
- 'character.update': roles.includes('mod'),
928
- 'rewards.distribute': roles.includes('admin'),
929
- 'character.data.write': roles.includes('mod'),
930
- 'character.inventory.write': roles.includes('mod'),
931
- 'profile.meta.write': roles.includes('mod'),
932
- // optionally narrower scopes:
933
- 'character.data.write:evolution.quest.*': roles.includes('mod'),
934
- };
935
-
936
- ctx.client.permissions = permissions;
937
-
938
- return {
939
- token: input.token,
940
- };
941
- }
942
- async syncGetPayloadsSince(
943
- input: RouterInput['syncGetPayloadsSince'],
944
- ctx: RouterContext
945
- ): Promise<RouterOutput['syncGetPayloadsSince']> {
946
- if (!input) throw new ARXError('NO_INPUT');
947
- log('Core.Service.syncGetPayloadsSince', input);
948
- const sinceDate = new Date(input.since);
949
- const payloads = await ctx.app.model.SeerPayload.find({
950
- createdDate: { $gt: sinceDate },
951
- })
952
- .lean()
953
- .exec();
954
- return { payloads };
955
- }
956
- // Account Methods
957
- async getAccount(input: RouterInput['getAccount'], ctx: RouterContext): Promise<RouterOutput['getAccount']> {
958
- if (!input) throw new ARXError('NO_INPUT');
959
- log('Core.Service.getAccount', input);
960
- const account = await ctx.app.model.Account.findOne(getFilter(input)).exec();
961
- if (!account) throw new Error('Account not found');
962
- return account as Account;
963
- }
964
- async getAccounts(ctx: RouterContext): Promise<RouterOutput['getAccounts']> {
965
- log('Core.Service.getAccounts');
966
- const accounts = await ctx.app.model.Account.find().exec();
967
- return accounts as Account[];
968
- }
969
- async createAccount(input: RouterInput['createAccount'], ctx: RouterContext): Promise<RouterOutput['createAccount']> {
970
- if (!input) throw new ARXError('NO_INPUT');
971
- log('Core.Service.createAccount', input);
972
- const account = await ctx.app.model.Account.create(input);
973
- return account as Account;
974
- }
975
- async updateAccount(input: RouterInput['updateAccount'], ctx: RouterContext): Promise<RouterOutput['updateAccount']> {
976
- if (!input) throw new ARXError('NO_INPUT');
977
- log('Core.Service.updateAccount', input);
978
- const updatedAccount = await ctx.app.model.Account.findByIdAndUpdate(input.where.id.equals, input.data, {
979
- new: true,
980
- })
981
- .lean()
982
- .exec();
983
- if (!updatedAccount) throw new Error('Account update failed');
984
- return updatedAccount as Account;
985
- }
986
- // Achievement Methods
987
- async getAchievement(
988
- input: RouterInput['getAchievement'],
989
- ctx: RouterContext
990
- ): Promise<RouterOutput['getAchievement']> {
991
- if (!input) throw new ARXError('NO_INPUT');
992
- log('Core.Service.getAchievement', input);
993
- const achievement = await ctx.app.model.Achievement.findOne(getFilter(input)).exec();
994
- if (!achievement) throw new Error('Achievement not found');
995
- return achievement as Achievement;
996
- }
997
- async getAchievements(ctx: RouterContext): Promise<RouterOutput['getAchievements']> {
998
- log('Core.Service.getAchievements');
999
- const achievements = await ctx.app.model.Achievement.find().exec();
1000
- return achievements as Achievement[];
1001
- }
1002
- async createAchievement(
1003
- input: RouterInput['createAchievement'],
1004
- ctx: RouterContext
1005
- ): Promise<RouterOutput['createAchievement']> {
1006
- if (!input) throw new ARXError('NO_INPUT');
1007
- log('Core.Service.createAchievement', input);
1008
- const achievement = await ctx.app.model.Achievement.create(input);
1009
- return achievement as Achievement;
1010
- }
1011
- async updateAchievement(
1012
- input: RouterInput['updateAchievement'],
1013
- ctx: RouterContext
1014
- ): Promise<RouterOutput['updateAchievement']> {
1015
- if (!input) throw new ARXError('NO_INPUT');
1016
- log('Core.Service.updateAchievement', input);
1017
- const updatedAchievement = await ctx.app.model.Achievement.findByIdAndUpdate(input.where.id.equals, input.data, {
1018
- new: true,
1019
- })
1020
- .lean()
1021
- .exec();
1022
- if (!updatedAchievement) throw new Error('Achievement update failed');
1023
- return updatedAchievement as Achievement;
1024
- }
1025
- async info(input: RouterInput['info'], ctx: RouterContext): Promise<RouterOutput['info']> {
1026
- return { version: '1.1.1' };
1027
- }
1028
- async stats(input: RouterInput['stats'], ctx: RouterContext): Promise<RouterOutput['stats']> {
1029
- if (!input) throw new ARXError('NO_INPUT');
1030
- log('Core.Service.stats');
1031
- const stats = await ctx.app.model.Stat.find().sort({ number: -1 }).limit(1).exec();
1032
- return stats.map((stat) => stat.toObject()) as Stat[];
1033
- }
1034
- // Act Methods
1035
- // Get Act
1036
- async getAct(input: RouterInput['getAct'], ctx: RouterContext): Promise<RouterOutput['getAct']> {
1037
- if (!input) throw new ARXError('NO_INPUT');
1038
- log('Core.Service.getAct', input);
1039
- const act = await ctx.app.model.Act.findOne(getFilter(input)).exec();
1040
- if (!act) throw new Error('Act not found');
1041
- return act as Act;
1042
- }
1043
- async getActs(input: RouterInput['getActs'], ctx: RouterContext): Promise<RouterOutput['getActs']> {
1044
- if (!input) throw new ARXError('NO_INPUT');
1045
- const filter = getFilter(input);
1046
- const limit = input.limit ?? 50;
1047
- const skip = input.skip ?? 0;
1048
- const [items, total] = await Promise.all([
1049
- ctx.app.model.Act.find(filter).skip(skip).limit(limit).lean().exec(),
1050
- ctx.app.model.Act.find(filter).countDocuments().exec(),
1051
- ]);
1052
- return { items, total };
1053
- }
1054
- // Create Act
1055
- async createAct(input: RouterInput['createAct'], ctx: RouterContext): Promise<RouterOutput['createAct']> {
1056
- if (!input) throw new ARXError('NO_INPUT');
1057
- log('Core.Service.createAct', input);
1058
- const act = await ctx.app.model.Act.create(input);
1059
- return act as Act;
1060
- }
1061
- // Update Act
1062
- async updateAct(input: RouterInput['updateAct'], ctx: RouterContext): Promise<RouterOutput['updateAct']> {
1063
- if (!input) throw new ARXError('NO_INPUT');
1064
- log('Core.Service.updateAct', input);
1065
- const updatedAct = await ctx.app.model.Act.findByIdAndUpdate(input.where.id.equals, input.data, { new: true })
1066
- .lean()
1067
- .exec();
1068
- if (!updatedAct) throw new Error('Act update failed');
1069
- return updatedAct as Act;
1070
- }
1071
- // Agent Methods
1072
- // Get Agent
1073
- async getAgent(input: RouterInput['getAgent'], ctx: RouterContext): Promise<RouterOutput['getAgent']> {
1074
- if (!input) throw new ARXError('NO_INPUT');
1075
- log('Core.Service.getAgent', input);
1076
- const agent = await ctx.app.model.Agent.findOne(getFilter(input)).exec();
1077
- if (!agent) throw new Error('Agent not found');
1078
- return agent as Agent;
1079
- }
1080
- // Create Agent
1081
- async createAgent(input: RouterInput['createAgent'], ctx: RouterContext): Promise<RouterOutput['createAgent']> {
1082
- if (!input) throw new ARXError('NO_INPUT');
1083
- log('Core.Service.createAgent', input);
1084
- const agent = await ctx.app.model.Agent.create(input);
1085
- return agent as Agent;
1086
- }
1087
- // Update Agent
1088
- async updateAgent(input: RouterInput['updateAgent'], ctx: RouterContext): Promise<RouterOutput['updateAgent']> {
1089
- if (!input) throw new ARXError('NO_INPUT');
1090
- log('Core.Service.updateAgent', input);
1091
- const updatedAgent = await ctx.app.model.Agent.findByIdAndUpdate(input.where.id.equals, input.data, { new: true })
1092
- .lean()
1093
- .exec();
1094
- if (!updatedAgent) throw new Error('Agent update failed');
1095
- return updatedAgent as Agent;
1096
- }
1097
- // Application Methods
1098
- // Get Application
1099
- async getApplication(
1100
- input: RouterInput['getApplication'],
1101
- ctx: RouterContext
1102
- ): Promise<RouterOutput['getApplication']> {
1103
- if (!input) throw new ARXError('NO_INPUT');
1104
- log('Core.Service.getApplication', input);
1105
- const application = await ctx.app.model.Application.findOne(getFilter(input)).exec();
1106
- if (!application) throw new Error('Application not found');
1107
- return application as Application;
1108
- }
1109
- // Create Application
1110
- async createApplication(
1111
- input: RouterInput['createApplication'],
1112
- ctx: RouterContext
1113
- ): Promise<RouterOutput['createApplication']> {
1114
- if (!input) throw new ARXError('NO_INPUT');
1115
- log('Core.Service.createApplication', input);
1116
- const application = await ctx.app.model.Application.create(input);
1117
- return application as Application;
1118
- }
1119
- // Update Application
1120
- async updateApplication(
1121
- input: RouterInput['updateApplication'],
1122
- ctx: RouterContext
1123
- ): Promise<RouterOutput['updateApplication']> {
1124
- if (!input) throw new ARXError('NO_INPUT');
1125
- log('Core.Service.updateApplication', input);
1126
- const updatedApplication = await ctx.app.model.Application.findByIdAndUpdate(input.where.id.equals, input.data, {
1127
- new: true,
1128
- })
1129
- .lean()
1130
- .exec();
1131
- if (!updatedApplication) throw new Error('Application update failed');
1132
- return updatedApplication as Application;
1133
- }
1134
- // Badge Methods
1135
- async getBadge(input: RouterInput['getBadge'], ctx: RouterContext): Promise<RouterOutput['getBadge']> {
1136
- if (!input) throw new ARXError('NO_INPUT');
1137
- log('Core.Service.getBadge', input);
1138
- const badge = await ctx.app.model.Badge.findOne(getFilter(input)).exec();
1139
- if (!badge) throw new Error('Badge not found');
1140
- return badge as Badge;
1141
- }
1142
- async createBadge(input: RouterInput['createBadge'], ctx: RouterContext): Promise<RouterOutput['createBadge']> {
1143
- if (!input) throw new ARXError('NO_INPUT');
1144
- log('Core.Service.createBadge', input);
1145
- const badge = await ctx.app.model.Badge.create(input);
1146
- return badge as Badge;
1147
- }
1148
- async updateBadge(input: RouterInput['updateBadge'], ctx: RouterContext): Promise<RouterOutput['updateBadge']> {
1149
- if (!input) throw new ARXError('NO_INPUT');
1150
- log('Core.Service.updateBadge', input);
1151
- const updatedBadge = await ctx.app.model.Badge.findByIdAndUpdate(input.where.id.equals, input.data, { new: true })
1152
- .lean()
1153
- .exec();
1154
- if (!updatedBadge) throw new Error('Badge update failed');
1155
- return updatedBadge as Badge;
1156
- }
1157
- // BattlePass Methods
1158
- async getBattlePass(input: RouterInput['getBattlePass'], ctx: RouterContext): Promise<RouterOutput['getBattlePass']> {
1159
- if (!input) throw new ARXError('NO_INPUT');
1160
- log('Core.Service.getBattlePass', input);
1161
- const battlePass = await ctx.app.model.BattlePass.findOne(getFilter(input)).exec();
1162
- if (!battlePass) throw new Error('BattlePass not found');
1163
- return battlePass as BattlePass;
1164
- }
1165
- async createBattlePass(
1166
- input: RouterInput['createBattlePass'],
1167
- ctx: RouterContext
1168
- ): Promise<RouterOutput['createBattlePass']> {
1169
- if (!input) throw new ARXError('NO_INPUT');
1170
- log('Core.Service.createBattlePass', input);
1171
- const battlePass = await ctx.app.model.BattlePass.create(input);
1172
- return battlePass as BattlePass;
1173
- }
1174
- async updateBattlePass(
1175
- input: RouterInput['updateBattlePass'],
1176
- ctx: RouterContext
1177
- ): Promise<RouterOutput['updateBattlePass']> {
1178
- if (!input) throw new ARXError('NO_INPUT');
1179
- log('Core.Service.updateBattlePass', input);
1180
- const updatedBattlePass = await ctx.app.model.BattlePass.findByIdAndUpdate(input.where.id.equals, input.data, {
1181
- new: true,
1182
- })
1183
- .lean()
1184
- .exec();
1185
- if (!updatedBattlePass) throw new Error('BattlePass update failed');
1186
- return updatedBattlePass as BattlePass;
1187
- }
1188
- // Biome Methods
1189
- async getBiome(input: RouterInput['getBiome'], ctx: RouterContext): Promise<RouterOutput['getBiome']> {
1190
- if (!input) throw new ARXError('NO_INPUT');
1191
- log('Core.Service.getBiome', input);
1192
- const biome = await ctx.app.model.Biome.findOne(getFilter(input)).exec();
1193
- if (!biome) throw new Error('Biome not found');
1194
- return biome as Biome;
1195
- }
1196
- async createBiome(input: RouterInput['createBiome'], ctx: RouterContext): Promise<RouterOutput['createBiome']> {
1197
- if (!input) throw new ARXError('NO_INPUT');
1198
- log('Core.Service.createBiome', input);
1199
- const biome = await ctx.app.model.Biome.create(input);
1200
- return biome as Biome;
1201
- }
1202
- async updateBiome(input: RouterInput['updateBiome'], ctx: RouterContext): Promise<RouterOutput['updateBiome']> {
1203
- if (!input) throw new ARXError('NO_INPUT');
1204
- log('Core.Service.updateBiome', input);
1205
- const updatedBiome = await ctx.app.model.Biome.findByIdAndUpdate(input.where.id.equals, input.data, { new: true })
1206
- .lean()
1207
- .exec();
1208
- if (!updatedBiome) throw new Error('Biome update failed');
1209
- return updatedBiome as Biome;
1210
- }
1211
- // BiomeFeature Methods
1212
- async getBiomeFeature(
1213
- input: RouterInput['getBiomeFeature'],
1214
- ctx: RouterContext
1215
- ): Promise<RouterOutput['getBiomeFeature']> {
1216
- if (!input) throw new ARXError('NO_INPUT');
1217
- log('Core.Service.getBiomeFeature', input);
1218
- const biomeFeature = await ctx.app.model.BiomeFeature.findOne(getFilter(input)).exec();
1219
- if (!biomeFeature) throw new Error('BiomeFeature not found');
1220
- return biomeFeature as BiomeFeature;
1221
- }
1222
- async createBiomeFeature(
1223
- input: RouterInput['createBiomeFeature'],
1224
- ctx: RouterContext
1225
- ): Promise<RouterOutput['createBiomeFeature']> {
1226
- if (!input) throw new ARXError('NO_INPUT');
1227
- log('Core.Service.createBiomeFeature', input);
1228
- const biomeFeature = await ctx.app.model.BiomeFeature.create(input);
1229
- return biomeFeature as BiomeFeature;
1230
- }
1231
- async updateBiomeFeature(
1232
- input: RouterInput['updateBiomeFeature'],
1233
- ctx: RouterContext
1234
- ): Promise<RouterOutput['updateBiomeFeature']> {
1235
- if (!input) throw new ARXError('NO_INPUT');
1236
- log('Core.Service.updateBiomeFeature', input);
1237
- const updatedBiomeFeature = await ctx.app.model.BiomeFeature.findByIdAndUpdate(input.where.id.equals, input.data, {
1238
- new: true,
1239
- })
1240
- .lean()
1241
- .exec();
1242
- if (!updatedBiomeFeature) throw new Error('BiomeFeature update failed');
1243
- return updatedBiomeFeature as BiomeFeature;
1244
- }
1245
- // Collection Methods
1246
- async getCollection(input: RouterInput['getCollection'], ctx: RouterContext): Promise<RouterOutput['getCollection']> {
1247
- if (!input) throw new ARXError('NO_INPUT');
1248
- log('Core.Service.getCollection', input);
1249
- const collection = await ctx.app.model.Collection.findOne(getFilter(input)).exec();
1250
- if (!collection) throw new Error('Collection not found');
1251
- return collection as Collection;
1252
- }
1253
- async createCollection(
1254
- input: RouterInput['createCollection'],
1255
- ctx: RouterContext
1256
- ): Promise<RouterOutput['createCollection']> {
1257
- if (!input) throw new ARXError('NO_INPUT');
1258
- log('Core.Service.createCollection', input);
1259
- const collection = await ctx.app.model.Collection.create(input);
1260
- return collection as Collection;
1261
- }
1262
- async updateCollection(
1263
- input: RouterInput['updateCollection'],
1264
- ctx: RouterContext
1265
- ): Promise<RouterOutput['updateCollection']> {
1266
- if (!input) throw new ARXError('NO_INPUT');
1267
- log('Core.Service.updateCollection', input);
1268
- const updatedCollection = await ctx.app.model.Collection.findByIdAndUpdate(input.where.id.equals, input.data, {
1269
- new: true,
1270
- })
1271
- .lean()
1272
- .exec();
1273
- if (!updatedCollection) throw new Error('Collection update failed');
1274
- return updatedCollection as Collection;
1275
- }
1276
- // Comment Methods
1277
- async getComment(input: RouterInput['getComment'], ctx: RouterContext): Promise<RouterOutput['getComment']> {
1278
- if (!input) throw new ARXError('NO_INPUT');
1279
- log('Core.Service.getComment', input);
1280
- const comment = await ctx.app.model.Comment.findOne(getFilter(input)).exec();
1281
- if (!comment) throw new Error('Comment not found');
1282
- return comment as Comment;
1283
- }
1284
- async createComment(input: RouterInput['createComment'], ctx: RouterContext): Promise<RouterOutput['createComment']> {
1285
- if (!input) throw new ARXError('NO_INPUT');
1286
- log('Core.Service.createComment', input);
1287
- const comment = await ctx.app.model.Comment.create(input);
1288
- return comment as Comment;
1289
- }
1290
- async updateComment(input: RouterInput['updateComment'], ctx: RouterContext): Promise<RouterOutput['updateComment']> {
1291
- if (!input) throw new ARXError('NO_INPUT');
1292
- log('Core.Service.updateComment', input);
1293
- const updatedComment = await ctx.app.model.Comment.findByIdAndUpdate(input.where.id.equals, input.data, {
1294
- new: true,
1295
- })
1296
- .lean()
1297
- .exec();
1298
- if (!updatedComment) throw new Error('Comment update failed');
1299
- return updatedComment as Comment;
1300
- }
1301
- // Community Methods
1302
- async getCommunity(input: RouterInput['getCommunity'], ctx: RouterContext): Promise<RouterOutput['getCommunity']> {
1303
- if (!input) throw new ARXError('NO_INPUT');
1304
- log('Core.Service.getCommunity', input);
1305
- const community = await ctx.app.model.Community.findOne(getFilter(input)).exec();
1306
- if (!community) throw new Error('Community not found');
1307
- return community as Community;
1308
- }
1309
- async createCommunity(
1310
- input: RouterInput['createCommunity'],
1311
- ctx: RouterContext
1312
- ): Promise<RouterOutput['createCommunity']> {
1313
- if (!input) throw new ARXError('NO_INPUT');
1314
- log('Core.Service.createCommunity', input);
1315
- const community = await ctx.app.model.Community.create(input);
1316
- return community as Community;
1317
- }
1318
- async updateCommunity(
1319
- input: RouterInput['updateCommunity'],
1320
- ctx: RouterContext
1321
- ): Promise<RouterOutput['updateCommunity']> {
1322
- if (!input) throw new ARXError('NO_INPUT');
1323
- log('Core.Service.updateCommunity', input);
1324
- const updatedCommunity = await ctx.app.model.Community.findByIdAndUpdate(input.where.id.equals, input.data, {
1325
- new: true,
1326
- })
1327
- .lean()
1328
- .exec();
1329
- if (!updatedCommunity) throw new Error('Community update failed');
1330
- return updatedCommunity as Community;
1331
- }
1332
- // Company Methods
1333
- async getCompany(input: RouterInput['getCompany'], ctx: RouterContext): Promise<RouterOutput['getCompany']> {
1334
- if (!input) throw new ARXError('NO_INPUT');
1335
- log('Core.Service.getCompany', input);
1336
- const company = await ctx.app.model.Company.findOne(getFilter(input)).exec();
1337
- if (!company) throw new Error('Company not found');
1338
- return company as Company;
1339
- }
1340
- async createCompany(input: RouterInput['createCompany'], ctx: RouterContext): Promise<RouterOutput['createCompany']> {
1341
- if (!input) throw new ARXError('NO_INPUT');
1342
- log('Core.Service.createCompany', input);
1343
- const company = await ctx.app.model.Company.create(input);
1344
- return company as Company;
1345
- }
1346
- async updateCompany(input: RouterInput['updateCompany'], ctx: RouterContext): Promise<RouterOutput['updateCompany']> {
1347
- if (!input) throw new ARXError('NO_INPUT');
1348
- log('Core.Service.updateCompany', input.where.id.equals, input.data);
1349
- const updatedCompany = await ctx.app.model.Company.findByIdAndUpdate(input.where.id.equals, input.data, {
1350
- new: true,
1351
- })
1352
- .lean()
1353
- .exec();
1354
- if (!updatedCompany) throw new Error('Company update failed');
1355
- return updatedCompany as Company;
1356
- }
1357
- // Data Methods
1358
- async getData(input: RouterInput['getData'], ctx: RouterContext): Promise<RouterOutput['getData']> {
1359
- if (!input) throw new ARXError('NO_INPUT');
1360
- log('Core.Service.getData', input.where.id.equals);
1361
- const data = await ctx.app.model.Data.findOne(getFilter(input)).exec();
1362
- if (!data) throw new Error('Data not found');
1363
- return data as Data;
1364
- }
1365
- async createData(input: RouterInput['createData'], ctx: RouterContext): Promise<RouterOutput['createData']> {
1366
- if (!input) throw new ARXError('NO_INPUT');
1367
- log('Core.Service.createData', input);
1368
- const data = await ctx.app.model.Data.create(input);
1369
- return data as Data;
1370
- }
1371
- async updateData(input: RouterInput['updateData'], ctx: RouterContext): Promise<RouterOutput['updateData']> {
1372
- if (!input) throw new ARXError('NO_INPUT');
1373
- log('Core.Service.updateData', input.where.id.equals, input.data);
1374
- const updatedData = await ctx.app.model.Data.findByIdAndUpdate(input.where.id.equals, input.data, { new: true })
1375
- .lean()
1376
- .exec();
1377
- if (!updatedData) throw new Error('Data update failed');
1378
- return updatedData as Data;
1379
- }
1380
- // Discussion Methods
1381
- async getDiscussion(input: RouterInput['getDiscussion'], ctx: RouterContext): Promise<RouterOutput['getDiscussion']> {
1382
- if (!input) throw new ARXError('NO_INPUT');
1383
- log('Core.Service.getDiscussion', input.where.id.equals);
1384
- const discussion = await ctx.app.model.Discussion.findOne(getFilter(input)).exec();
1385
- if (!discussion) throw new Error('Discussion not found');
1386
- return discussion as Discussion;
1387
- }
1388
- async createDiscussion(
1389
- input: RouterInput['createDiscussion'],
1390
- ctx: RouterContext
1391
- ): Promise<RouterOutput['createDiscussion']> {
1392
- if (!input) throw new ARXError('NO_INPUT');
1393
- log('Core.Service.createDiscussion', input);
1394
- const discussion = await ctx.app.model.Discussion.create(input);
1395
- return discussion as Discussion;
1396
- }
1397
- async updateDiscussion(
1398
- input: RouterInput['updateDiscussion'],
1399
- ctx: RouterContext
1400
- ): Promise<RouterOutput['updateDiscussion']> {
1401
- if (!input) throw new ARXError('NO_INPUT');
1402
- log('Core.Service.updateDiscussion', input);
1403
- const updatedDiscussion = await ctx.app.model.Discussion.findByIdAndUpdate(input.where.id.equals, input.data, {
1404
- new: true,
1405
- })
1406
- .lean()
1407
- .exec();
1408
- if (!updatedDiscussion) throw new Error('Discussion update failed');
1409
- return updatedDiscussion as Discussion;
1410
- }
1411
- // // Procedure Methods
1412
- // async runProcedure(input: RouterInput['runProcedure'], ctx: RouterContext): Promise<RouterOutput['runProcedure']> {
1413
- // if (!input) throw new ARXError('NO_INPUT');
1414
- // log('Core.Service.runProcedure', input);
1415
- // // 1) Load procedure doc from Mongo by key (latest version or exact match)
1416
- // const procDoc = await ctx.app.model.Procedure.findOne({ key: input.key }).lean().exec();
1417
- // if (!procDoc) throw new ARXError('PROCEDURE_NOT_FOUND');
1418
-
1419
- // // 2) migrate v1 → v2 if needed
1420
- // const proc = migrateProcedure(procDoc); // returns { run: ProcedureRunStep[] ... }
1421
-
1422
- // // 3) permission checks
1423
- // // proc.run steps may declare permission; enforce in ctx
1424
- // for (const step of proc.run) {
1425
- // if (step.permission) {
1426
- // await ctx.auth.require(step.permission);
1427
- // }
1428
- // }
1429
-
1430
- // // 4) execute: seer mode steps may themselves resolve to inline patches or connector calls
1431
- // // But your new rule is: on seer, you decide what happens.
1432
- // const character = await ctx.character();
1433
- // const before = character.data || {};
1434
-
1435
- // const patchesApplied: any[] = [];
1436
-
1437
- // for (const step of proc.run) {
1438
- // if (step.mode === 'inline') {
1439
- // // evaluate patch formula in a sandboxed evaluator on server
1440
- // const patchOps = evalPatch(step.patch, { character: { data: before }, args: input.args });
1441
- // applyPatchesToCharacter(character, patchOps);
1442
- // patchesApplied.push(...patchOps);
1443
- // continue;
1444
- // }
1445
-
1446
- // if (step.mode === 'seer') {
1447
- // // This can either:
1448
- // // - call a TRPC/internal service mutation
1449
- // // - or interpret step.mutation as "quest.claimReward" etc
1450
- // const result = await ctx.seer.executeMutation(step.mutation!, step.input ?? input.args);
1451
-
1452
- // // result could return patches or direct updated data
1453
- // if (result?.patches) {
1454
- // applyPatchesToCharacter(character, result.patches);
1455
- // patchesApplied.push(...result.patches);
1456
- // }
1457
- // }
1458
- // }
1459
-
1460
- // await character.save();
1461
-
1462
- // return { ok: true, patchesApplied, characterData: character.data };
1463
- // }
1464
-
1465
- // Energy Methods
1466
- async getEnergy(input: RouterInput['getEnergy'], ctx: RouterContext): Promise<RouterOutput['getEnergy']> {
1467
- if (!input) throw new ARXError('NO_INPUT');
1468
- log('Core.Service.getEnergy', input);
1469
- const energy = await ctx.app.model.Energy.findOne(getFilter(input)).exec();
1470
- if (!energy) throw new Error('Energy not found');
1471
- return energy as Energy;
1472
- }
1473
- async getEnergies(input: RouterInput['getEnergies'], ctx: RouterContext): Promise<RouterOutput['getEnergies']> {
1474
- if (!input) throw new ARXError('NO_INPUT');
1475
- log('Core.Service.getEnergies', input);
1476
- const filter = getFilter(input);
1477
- const limit = input.limit ?? 50;
1478
- const skip = input.skip ?? 0;
1479
- const [items, total] = await Promise.all([
1480
- ctx.app.model.Energy.find(filter).skip(skip).limit(limit).lean().exec(),
1481
- ctx.app.model.Energy.find(filter).countDocuments().exec(),
1482
- ]);
1483
- return { items, total };
1484
- }
1485
- async createEnergy(input: RouterInput['createEnergy'], ctx: RouterContext): Promise<RouterOutput['createEnergy']> {
1486
- if (!input) throw new ARXError('NO_INPUT');
1487
- log('Core.Service.createEnergy', input);
1488
- const energy = await ctx.app.model.Energy.create(input);
1489
- return energy as Energy;
1490
- }
1491
- async updateEnergy(input: RouterInput['updateEnergy'], ctx: RouterContext): Promise<RouterOutput['updateEnergy']> {
1492
- if (!input) throw new ARXError('NO_INPUT');
1493
- log('Core.Service.updateEnergy', input);
1494
- const updatedEnergy = await ctx.app.model.Energy.findByIdAndUpdate(input.where.id.equals, { new: true })
1495
- .lean()
1496
- .exec();
1497
- if (!updatedEnergy) throw new Error('Energy update failed');
1498
- return updatedEnergy as Energy;
1499
- }
1500
- // Event Methods
1501
- async getEvent(input: RouterInput['getEvent'], ctx: RouterContext): Promise<RouterOutput['getEvent']> {
1502
- if (!input) throw new ARXError('NO_INPUT');
1503
- log('Core.Service.getEvent', input);
1504
- const event = await ctx.app.model.Event.findOne(getFilter(input)).exec();
1505
- if (!event) throw new Error('Event not found');
1506
- return event as Event;
1507
- }
1508
- async createEvent(input: RouterInput['createEvent'], ctx: RouterContext): Promise<RouterOutput['createEvent']> {
1509
- if (!input) throw new ARXError('NO_INPUT');
1510
- log('Core.Service.createEvent', input);
1511
- const event = await ctx.app.model.Event.create(input);
1512
- return event as Event;
1513
- }
1514
- async updateEvent(input: RouterInput['updateEvent'], ctx: RouterContext): Promise<RouterOutput['updateEvent']> {
1515
- if (!input) throw new ARXError('NO_INPUT');
1516
- log('Core.Service.updateEvent', input);
1517
- const updatedEvent = await ctx.app.model.Event.findByIdAndUpdate(input.where.id.equals, input.data, { new: true })
1518
- .lean()
1519
- .exec();
1520
- if (!updatedEvent) throw new Error('Event update failed');
1521
- return updatedEvent as Event;
1522
- }
1523
- // File Methods
1524
- async getFile(input: RouterInput['getFile'], ctx: RouterContext): Promise<RouterOutput['getFile']> {
1525
- if (!input) throw new ARXError('NO_INPUT');
1526
- log('Core.Service.getFile', input);
1527
- const file = await ctx.app.model.File.findOne(getFilter(input)).exec();
1528
- if (!file) throw new Error('File not found');
1529
- return file as File;
1530
- }
1531
- async createFile(input: RouterInput['createFile'], ctx: RouterContext): Promise<RouterOutput['createFile']> {
1532
- if (!input) throw new ARXError('NO_INPUT');
1533
- log('Core.Service.createFile', input);
1534
- const file = await ctx.app.model.File.create(input);
1535
- return file as File;
1536
- }
1537
- async updateFile(input: RouterInput['updateFile'], ctx: RouterContext): Promise<RouterOutput['updateFile']> {
1538
- if (!input) throw new ARXError('NO_INPUT');
1539
- log('Core.Service.updateFile', input);
1540
- const updatedFile = await ctx.app.model.File.findByIdAndUpdate(input.where.id.equals, input.data, { new: true })
1541
- .lean()
1542
- .exec();
1543
- if (!updatedFile) throw new Error('File update failed');
1544
- return updatedFile as File;
1545
- }
1546
- // Galaxy Methods
1547
- async getGalaxy(input: RouterInput['getGalaxy'], ctx: RouterContext): Promise<RouterOutput['getGalaxy']> {
1548
- if (!input) throw new ARXError('NO_INPUT');
1549
- log('Core.Service.getGalaxy', input);
1550
- const galaxy = await ctx.app.model.Galaxy.findOne(getFilter(input)).exec();
1551
- if (!galaxy) throw new Error('Galaxy not found');
1552
- return galaxy as Galaxy;
1553
- }
1554
- async createGalaxy(input: RouterInput['createGalaxy'], ctx: RouterContext): Promise<RouterOutput['createGalaxy']> {
1555
- if (!input) throw new ARXError('NO_INPUT');
1556
- log('Core.Service.createGalaxy', input);
1557
- const galaxy = await ctx.app.model.Galaxy.create(input);
1558
- return galaxy as Galaxy;
1559
- }
1560
- async updateGalaxy(input: RouterInput['updateGalaxy'], ctx: RouterContext): Promise<RouterOutput['updateGalaxy']> {
1561
- if (!input) throw new ARXError('NO_INPUT');
1562
- log('Core.Service.updateGalaxy', input);
1563
- const updatedGalaxy = await ctx.app.model.Galaxy.findByIdAndUpdate(input.where.id.equals, { new: true })
1564
- .lean()
1565
- .exec();
1566
- if (!updatedGalaxy) throw new Error('Galaxy update failed');
1567
- return updatedGalaxy as Galaxy;
1568
- }
1569
- // Guide Methods
1570
- async getGuide(input: RouterInput['getGuide'], ctx: RouterContext): Promise<RouterOutput['getGuide']> {
1571
- if (!input) throw new ARXError('NO_INPUT');
1572
- log('Core.Service.getGuide', input);
1573
- const guide = await ctx.app.model.Guide.findOne(getFilter(input)).exec();
1574
- if (!guide) throw new Error('Guide not found');
1575
- return guide as Guide;
1576
- }
1577
- async createGuide(input: RouterInput['createGuide'], ctx: RouterContext): Promise<RouterOutput['createGuide']> {
1578
- if (!input) throw new ARXError('NO_INPUT');
1579
- log('Core.Service.createGuide', input);
1580
- const guide = await ctx.app.model.Guide.create(input);
1581
- return guide as Guide;
1582
- }
1583
- async updateGuide(input: RouterInput['updateGuide'], ctx: RouterContext): Promise<RouterOutput['updateGuide']> {
1584
- if (!input) throw new ARXError('NO_INPUT');
1585
- log('Core.Service.updateGuide', input);
1586
- const updatedGuide = await ctx.app.model.Guide.findByIdAndUpdate(input.where.id.equals, { new: true })
1587
- .lean()
1588
- .exec();
1589
- if (!updatedGuide) throw new Error('Guide update failed');
1590
- return updatedGuide as Guide;
1591
- }
1592
- // Idea Methods
1593
- async getIdea(input: RouterInput['getIdea'], ctx: RouterContext): Promise<RouterOutput['getIdea']> {
1594
- if (!input) throw new ARXError('NO_INPUT');
1595
- log('Core.Service.getIdea', input);
1596
- const idea = await ctx.app.model.Idea.findOne(getFilter(input)).exec();
1597
- if (!idea) throw new Error('Idea not found');
1598
- return idea as Idea;
1599
- }
1600
- async createIdea(input: RouterInput['createIdea'], ctx: RouterContext): Promise<RouterOutput['createIdea']> {
1601
- if (!input) throw new ARXError('NO_INPUT');
1602
- log('Core.Service.createIdea', input);
1603
- const idea = await ctx.app.model.Idea.create(input);
1604
- return idea as Idea;
1605
- }
1606
- async updateIdea(input: RouterInput['updateIdea'], ctx: RouterContext): Promise<RouterOutput['updateIdea']> {
1607
- if (!input) throw new ARXError('NO_INPUT');
1608
- log('Core.Service.updateIdea', input);
1609
- const updatedIdea = await ctx.app.model.Idea.findByIdAndUpdate(input.where.id.equals, { new: true }).exec();
1610
- if (!updatedIdea) throw new Error('Idea update failed');
1611
- return updatedIdea as Idea;
1612
- }
1613
- // Leaderboard Methods
1614
- async getLeaderboard(
1615
- input: RouterInput['getLeaderboard'],
1616
- ctx: RouterContext
1617
- ): Promise<RouterOutput['getLeaderboard']> {
1618
- if (!input) throw new ARXError('NO_INPUT');
1619
- log('Core.Service.getLeaderboard', input);
1620
- const leaderboard = await ctx.app.model.Leaderboard.findOne(getFilter(input)).exec();
1621
- if (!leaderboard) throw new Error('Leaderboard not found');
1622
- return leaderboard as Leaderboard;
1623
- }
1624
- async createLeaderboard(
1625
- input: RouterInput['createLeaderboard'],
1626
- ctx: RouterContext
1627
- ): Promise<RouterOutput['createLeaderboard']> {
1628
- if (!input) throw new ARXError('NO_INPUT');
1629
- log('Core.Service.createLeaderboard', input);
1630
- const leaderboard = await ctx.app.model.Leaderboard.create(input);
1631
- return leaderboard as Leaderboard;
1632
- }
1633
- async updateLeaderboard(
1634
- input: RouterInput['updateLeaderboard'],
1635
- ctx: RouterContext
1636
- ): Promise<RouterOutput['updateLeaderboard']> {
1637
- if (!input) throw new ARXError('NO_INPUT');
1638
- log('Core.Service.updateLeaderboard', input);
1639
- const updatedLeaderboard = await ctx.app.model.Leaderboard.findByIdAndUpdate(input.where.id.equals, {
1640
- new: true,
1641
- })
1642
- .lean()
1643
- .exec();
1644
- if (!updatedLeaderboard) throw new Error('Leaderboard update failed');
1645
- return updatedLeaderboard as Leaderboard;
1646
- }
1647
- // Log Methods
1648
- async getLog(input: RouterInput['getLog'], ctx: RouterContext): Promise<RouterOutput['getLog']> {
1649
- if (!input) throw new ARXError('NO_INPUT');
1650
- log('Core.Service.getLog', input);
1651
- const item = await ctx.app.model.Log.findOne(getFilter(input)).exec();
1652
- if (!item) throw new Error('Log not found');
1653
- return item as Log;
1654
- }
1655
- async createLog(input: RouterInput['createLog'], ctx: RouterContext): Promise<RouterOutput['createLog']> {
1656
- if (!input) throw new ARXError('NO_INPUT');
1657
- log('Core.Service.createLog', input);
1658
- const item = await ctx.app.model.Log.create(input);
1659
- return item as Log;
1660
- }
1661
- async updateLog(input: RouterInput['updateLog'], ctx: RouterContext): Promise<RouterOutput['updateLog']> {
1662
- if (!input) throw new ARXError('NO_INPUT');
1663
- log('Core.Service.updateLog', input);
1664
- const item = await ctx.app.model.Log.findByIdAndUpdate(input.where.id.equals, { new: true }).exec();
1665
- if (!item) throw new Error('Log update failed');
1666
- return item as Log;
1667
- }
1668
- // Lore Methods
1669
- async getLore(input: RouterInput['getLore'], ctx: RouterContext): Promise<RouterOutput['getLore']> {
1670
- if (!input) throw new ARXError('NO_INPUT');
1671
- log('Core.Service.getLore', input);
1672
- const lore = await ctx.app.model.Lore.findOne(getFilter(input)).exec();
1673
- if (!lore) throw new Error('Lore not found');
1674
- return lore as Lore;
1675
- }
1676
- async createLore(input: RouterInput['createLore'], ctx: RouterContext): Promise<RouterOutput['createLore']> {
1677
- if (!input) throw new ARXError('NO_INPUT');
1678
- log('Core.Service.createLore', input);
1679
- const lore = await ctx.app.model.Lore.create(input);
1680
- return lore as Lore;
1681
- }
1682
- async updateLore(input: RouterInput['updateLore'], ctx: RouterContext): Promise<RouterOutput['updateLore']> {
1683
- if (!input) throw new ARXError('NO_INPUT');
1684
- log('Core.Service.updateLore', input);
1685
- const updatedLore = await ctx.app.model.Lore.findByIdAndUpdate(input.where.id.equals, { new: true }).exec();
1686
- if (!updatedLore) throw new Error('Lore update failed');
1687
- return updatedLore as Lore;
1688
- }
1689
- // Memory Methods
1690
- async getMemory(input: RouterInput['getMemory'], ctx: RouterContext): Promise<RouterOutput['getMemory']> {
1691
- if (!input) throw new ARXError('NO_INPUT');
1692
- log('Core.Service.getMemory', input);
1693
- const memory = await ctx.app.model.Memory.findOne(getFilter(input)).exec();
1694
- if (!memory) throw new Error('Memory not found');
1695
- return memory as Memory;
1696
- }
1697
- async createMemory(input: RouterInput['createMemory'], ctx: RouterContext): Promise<RouterOutput['createMemory']> {
1698
- if (!input) throw new ARXError('NO_INPUT');
1699
- log('Core.Service.createMemory', input);
1700
- const memory = await ctx.app.model.Memory.create(input);
1701
- return memory as Memory;
1702
- }
1703
- async updateMemory(input: RouterInput['updateMemory'], ctx: RouterContext): Promise<RouterOutput['updateMemory']> {
1704
- if (!input) throw new ARXError('NO_INPUT');
1705
- log('Core.Service.updateMemory', input);
1706
- const updatedMemory = await ctx.app.model.Memory.findByIdAndUpdate(input.where.id.equals, { new: true })
1707
- .lean()
1708
- .exec();
1709
- if (!updatedMemory) throw new Error('Memory update failed');
1710
- return updatedMemory as Memory;
1711
- }
1712
- // Message Methods
1713
- async getMessage(input: RouterInput['getMessage'], ctx: RouterContext): Promise<RouterOutput['getMessage']> {
1714
- if (!input) throw new ARXError('NO_INPUT');
1715
- log('Core.Service.getMessage', input);
1716
- const message = await ctx.app.model.Message.findOne(getFilter(input)).exec();
1717
- if (!message) throw new Error('Message not found');
1718
- return message as Message;
1719
- }
1720
- async createMessage(input: RouterInput['createMessage'], ctx: RouterContext): Promise<RouterOutput['createMessage']> {
1721
- if (!input) throw new ARXError('NO_INPUT');
1722
- log('Core.Service.createMessage', input);
1723
- const message = await ctx.app.model.Message.create(input);
1724
- return message as Message;
1725
- }
1726
- async updateMessage(input: RouterInput['updateMessage'], ctx: RouterContext): Promise<RouterOutput['updateMessage']> {
1727
- if (!input) throw new ARXError('NO_INPUT');
1728
- log('Core.Service.updateMessage', input);
1729
- const updatedMessage = await ctx.app.model.Message.findByIdAndUpdate(input.where.id.equals, { new: true })
1730
- .lean()
1731
- .exec();
1732
- if (!updatedMessage) throw new Error('Message update failed');
1733
- return updatedMessage as Message;
1734
- }
1735
- // Metaverse Methods
1736
- async getMetaverse(input: RouterInput['getMetaverse'], ctx: RouterContext): Promise<RouterOutput['getMetaverse']> {
1737
- if (!input) throw new ARXError('NO_INPUT');
1738
- log('Core.Service.getMetaverse', input);
1739
- const metaverse = await ctx.app.model.Metaverse.findOne(getFilter(input)).exec();
1740
- if (!metaverse) throw new Error('Metaverse not found');
1741
- return metaverse as Metaverse;
1742
- }
1743
- async createMetaverse(
1744
- input: RouterInput['createMetaverse'],
1745
- ctx: RouterContext
1746
- ): Promise<RouterOutput['createMetaverse']> {
1747
- if (!input) throw new ARXError('NO_INPUT');
1748
- log('Core.Service.createMetaverse', input);
1749
- const metaverse = await ctx.app.model.Metaverse.create(input);
1750
- return metaverse as Metaverse;
1751
- }
1752
- async updateMetaverse(
1753
- input: RouterInput['updateMetaverse'],
1754
- ctx: RouterContext
1755
- ): Promise<RouterOutput['updateMetaverse']> {
1756
- if (!input) throw new ARXError('NO_INPUT');
1757
- log('Core.Service.updateMetaverse', input);
1758
- const updatedMetaverse = await ctx.app.model.Metaverse.findByIdAndUpdate(input.where.id.equals, {
1759
- new: true,
1760
- })
1761
- .lean()
1762
- .exec();
1763
- if (!updatedMetaverse) throw new Error('Metaverse update failed');
1764
- return updatedMetaverse as Metaverse;
1765
- }
1766
- // NewsArticle Methods
1767
- async getNewsArticle(
1768
- input: RouterInput['getNewsArticle'],
1769
- ctx: RouterContext
1770
- ): Promise<RouterOutput['getNewsArticle']> {
1771
- if (!input) throw new ARXError('NO_INPUT');
1772
- log('Core.Service.getNewsArticle', input);
1773
- const newsArticle = await ctx.app.model.NewsArticle.findOne(getFilter(input)).exec();
1774
- if (!newsArticle) throw new Error('NewsArticle not found');
1775
- return newsArticle as NewsArticle;
1776
- }
1777
- async createNewsArticle(
1778
- input: RouterInput['createNewsArticle'],
1779
- ctx: RouterContext
1780
- ): Promise<RouterOutput['createNewsArticle']> {
1781
- if (!input) throw new ARXError('NO_INPUT');
1782
- log('Core.Service.createNewsArticle', input);
1783
- const newsArticle = await ctx.app.model.NewsArticle.create(input);
1784
- return newsArticle as NewsArticle;
1785
- }
1786
- async updateNewsArticle(
1787
- input: RouterInput['updateNewsArticle'],
1788
- ctx: RouterContext
1789
- ): Promise<RouterOutput['updateNewsArticle']> {
1790
- if (!input) throw new ARXError('NO_INPUT');
1791
- log('Core.Service.updateNewsArticle', input);
1792
- const updatedNewsArticle = await ctx.app.model.NewsArticle.findByIdAndUpdate(input.where.id.equals, {
1793
- new: true,
1794
- })
1795
- .lean()
1796
- .exec();
1797
- if (!updatedNewsArticle) throw new Error('NewsArticle update failed');
1798
- return updatedNewsArticle as NewsArticle;
1799
- }
1800
- // Npc Methods
1801
- async getNpc(input: RouterInput['getNpc'], ctx: RouterContext): Promise<RouterOutput['getNpc']> {
1802
- if (!input) throw new ARXError('NO_INPUT');
1803
- log('Core.Service.getNpc', input);
1804
- const npc = await ctx.app.model.Npc.findOne(getFilter(input)).exec();
1805
- if (!npc) throw new Error('Npc not found');
1806
- return npc as Npc;
1807
- }
1808
- async createNpc(input: RouterInput['createNpc'], ctx: RouterContext): Promise<RouterOutput['createNpc']> {
1809
- if (!input) throw new ARXError('NO_INPUT');
1810
- log('Core.Service.createNpc', input);
1811
- const npc = await ctx.app.model.Npc.create(input);
1812
- return npc as Npc;
1813
- }
1814
- async updateNpc(input: RouterInput['updateNpc'], ctx: RouterContext): Promise<RouterOutput['updateNpc']> {
1815
- if (!input) throw new ARXError('NO_INPUT');
1816
- log('Core.Service.updateNpc', input);
1817
- const updatedNpc = await ctx.app.model.Npc.findByIdAndUpdate(input.where.id.equals, { new: true }).exec();
1818
- if (!updatedNpc) throw new Error('Npc update failed');
1819
- return updatedNpc as Npc;
1820
- }
1821
- // Offer Methods
1822
- async getOffer(input: RouterInput['getOffer'], ctx: RouterContext): Promise<RouterOutput['getOffer']> {
1823
- if (!input) throw new ARXError('NO_INPUT');
1824
- log('Core.Service.getOffer', input);
1825
- const offer = await ctx.app.model.Offer.findOne(getFilter(input)).exec();
1826
- if (!offer) throw new Error('Offer not found');
1827
- return offer as Offer;
1828
- }
1829
- async createOffer(input: RouterInput['createOffer'], ctx: RouterContext): Promise<RouterOutput['createOffer']> {
1830
- if (!input) throw new ARXError('NO_INPUT');
1831
- log('Core.Service.createOffer', input);
1832
- const offer = await ctx.app.model.Offer.create(input);
1833
- return offer as Offer;
1834
- }
1835
- async updateOffer(input: RouterInput['updateOffer'], ctx: RouterContext): Promise<RouterOutput['updateOffer']> {
1836
- if (!input) throw new ARXError('NO_INPUT');
1837
- log('Core.Service.updateOffer', input);
1838
- const updatedOffer = await ctx.app.model.Offer.findByIdAndUpdate(input.where.id.equals, { new: true })
1839
- .lean()
1840
- .exec();
1841
- if (!updatedOffer) throw new Error('Offer update failed');
1842
- return updatedOffer as Offer;
1843
- }
1844
- // Omniverse Methods
1845
- async getOmniverse(input: RouterInput['getOmniverse'], ctx: RouterContext): Promise<RouterOutput['getOmniverse']> {
1846
- if (!input) throw new ARXError('NO_INPUT');
1847
- log('Core.Service.getOmniverse', input);
1848
- const omniverse = await ctx.app.model.Omniverse.findOne(getFilter(input)).exec();
1849
- if (!omniverse) throw new Error('Omniverse not found');
1850
- return omniverse as Omniverse;
1851
- }
1852
- async createOmniverse(
1853
- input: RouterInput['createOmniverse'],
1854
- ctx: RouterContext
1855
- ): Promise<RouterOutput['createOmniverse']> {
1856
- if (!input) throw new ARXError('NO_INPUT');
1857
- log('Core.Service.createOmniverse', input);
1858
- const omniverse = await ctx.app.model.Omniverse.create(input);
1859
- return omniverse as Omniverse;
1860
- }
1861
- async updateOmniverse(
1862
- input: RouterInput['updateOmniverse'],
1863
- ctx: RouterContext
1864
- ): Promise<RouterOutput['updateOmniverse']> {
1865
- if (!input) throw new ARXError('NO_INPUT');
1866
- log('Core.Service.updateOmniverse', input);
1867
- const updatedOmniverse = await ctx.app.model.Omniverse.findByIdAndUpdate(input.where.id.equals, {
1868
- new: true,
1869
- })
1870
- .lean()
1871
- .exec();
1872
- if (!updatedOmniverse) throw new Error('Omniverse update failed');
1873
- return updatedOmniverse as Omniverse;
1874
- }
1875
- // Order Methods
1876
- async getOrder(input: RouterInput['getOrder'], ctx: RouterContext): Promise<RouterOutput['getOrder']> {
1877
- if (!input) throw new ARXError('NO_INPUT');
1878
- log('Core.Service.getOrder', input);
1879
- const order = await ctx.app.model.Order.findOne(getFilter(input)).exec();
1880
- if (!order) throw new Error('Order not found');
1881
- return order as Order;
1882
- }
1883
- async createOrder(input: RouterInput['createOrder'], ctx: RouterContext): Promise<RouterOutput['createOrder']> {
1884
- if (!input) throw new ARXError('NO_INPUT');
1885
- log('Core.Service.createOrder', input);
1886
- const order = await ctx.app.model.Order.create(input);
1887
- return order as Order;
1888
- }
1889
- async updateOrder(input: RouterInput['updateOrder'], ctx: RouterContext): Promise<RouterOutput['updateOrder']> {
1890
- if (!input) throw new ARXError('NO_INPUT');
1891
- log('Core.Service.updateOrder', input);
1892
- const updatedOrder = await ctx.app.model.Order.findByIdAndUpdate(input.where.id.equals, { new: true })
1893
- .lean()
1894
- .exec();
1895
- if (!updatedOrder) throw new Error('Order update failed');
1896
- return updatedOrder as Order;
1897
- }
1898
- // Payment Methods
1899
- async getPayment(input: RouterInput['getPayment'], ctx: RouterContext): Promise<RouterOutput['getPayment']> {
1900
- if (!input) throw new ARXError('NO_INPUT');
1901
- log('Core.Service.getPayment', input);
1902
- const payment = await ctx.app.model.Payment.findOne(getFilter(input)).exec();
1903
- if (!payment) throw new Error('Payment not found');
1904
- return payment as Payment;
1905
- }
1906
- async createPayment(input: RouterInput['createPayment'], ctx: RouterContext): Promise<RouterOutput['createPayment']> {
1907
- if (!input) throw new ARXError('NO_INPUT');
1908
- log('Core.Service.createPayment', input);
1909
- const payment = await ctx.app.model.Payment.create(input);
1910
- return payment as Payment;
1911
- }
1912
- async updatePayment(input: RouterInput['updatePayment'], ctx: RouterContext): Promise<RouterOutput['updatePayment']> {
1913
- if (!input) throw new ARXError('NO_INPUT');
1914
- log('Core.Service.updatePayment', input);
1915
- const updatedPayment = await ctx.app.model.Payment.findByIdAndUpdate(input.where.id.equals, { new: true })
1916
- .lean()
1917
- .exec();
1918
- if (!updatedPayment) throw new Error('Payment update failed');
1919
- return updatedPayment as Payment;
1920
- }
1921
- // Permission Methods
1922
- async getPermission(input: RouterInput['getPermission'], ctx: RouterContext): Promise<RouterOutput['getPermission']> {
1923
- if (!input) throw new ARXError('NO_INPUT');
1924
- log('Core.Service.getPermission', input);
1925
- const permission = await ctx.app.model.Permission.findOne(getFilter(input)).exec();
1926
- if (!permission) throw new Error('Permission not found');
1927
- return permission as Permission;
1928
- }
1929
- async createPermission(
1930
- input: RouterInput['createPermission'],
1931
- ctx: RouterContext
1932
- ): Promise<RouterOutput['createPermission']> {
1933
- if (!input) throw new ARXError('NO_INPUT');
1934
- log('Core.Service.createPermission', input);
1935
- const permission = await ctx.app.model.Permission.create(input);
1936
- return permission as Permission;
1937
- }
1938
- async updatePermission(
1939
- input: RouterInput['updatePermission'],
1940
- ctx: RouterContext
1941
- ): Promise<RouterOutput['updatePermission']> {
1942
- if (!input) throw new ARXError('NO_INPUT');
1943
- log('Core.Service.updatePermission', input);
1944
- const updatedPermission = await ctx.app.model.Permission.findByIdAndUpdate(input.where.id.equals, {
1945
- new: true,
1946
- })
1947
- .lean()
1948
- .exec();
1949
- if (!updatedPermission) throw new Error('Permission update failed');
1950
- return updatedPermission as Permission;
1951
- }
1952
- // Person Methods
1953
- async getPerson(input: RouterInput['getPerson'], ctx: RouterContext): Promise<RouterOutput['getPerson']> {
1954
- if (!input) throw new ARXError('NO_INPUT');
1955
- log('Core.Service.getPerson', input);
1956
- const person = await ctx.app.model.Person.findOne(getFilter(input)).exec();
1957
- if (!person) throw new Error('Person not found');
1958
- return person as Person;
1959
- }
1960
- async createPerson(input: RouterInput['createPerson'], ctx: RouterContext): Promise<RouterOutput['createPerson']> {
1961
- if (!input) throw new ARXError('NO_INPUT');
1962
- log('Core.Service.createPerson', input);
1963
- const person = await ctx.app.model.Person.create(input);
1964
- return person as Person;
1965
- }
1966
- async updatePerson(input: RouterInput['updatePerson'], ctx: RouterContext): Promise<RouterOutput['updatePerson']> {
1967
- if (!input) throw new ARXError('NO_INPUT');
1968
- log('Core.Service.updatePerson', input);
1969
- const updatedPerson = await ctx.app.model.Person.findByIdAndUpdate(input.where.id.equals, { new: true })
1970
- .lean()
1971
- .exec();
1972
- if (!updatedPerson) throw new Error('Person update failed');
1973
- return updatedPerson as Person;
1974
- }
1975
- // Planet Methods
1976
- async getPlanet(input: RouterInput['getPlanet'], ctx: RouterContext): Promise<RouterOutput['getPlanet']> {
1977
- if (!input) throw new ARXError('NO_INPUT');
1978
- log('Core.Service.getPlanet', input);
1979
- const planet = await ctx.app.model.Planet.findOne(getFilter(input)).exec();
1980
- if (!planet) throw new Error('Planet not found');
1981
- return planet as Planet;
1982
- }
1983
- async createPlanet(input: RouterInput['createPlanet'], ctx: RouterContext): Promise<RouterOutput['createPlanet']> {
1984
- if (!input) throw new ARXError('NO_INPUT');
1985
- log('Core.Service.createPlanet', input);
1986
- const planet = await ctx.app.model.Planet.create(input);
1987
- return planet as Planet;
1988
- }
1989
- async updatePlanet(input: RouterInput['updatePlanet'], ctx: RouterContext): Promise<RouterOutput['updatePlanet']> {
1990
- if (!input) throw new ARXError('NO_INPUT');
1991
- log('Core.Service.updatePlanet', input);
1992
- const updatedPlanet = await ctx.app.model.Planet.findByIdAndUpdate(input.where.id.equals, { new: true })
1993
- .lean()
1994
- .exec();
1995
- if (!updatedPlanet) throw new Error('Planet update failed');
1996
- return updatedPlanet as Planet;
1997
- }
1998
- // Poll Methods
1999
- async getPoll(input: RouterInput['getPoll'], ctx: RouterContext): Promise<RouterOutput['getPoll']> {
2000
- if (!input) throw new ARXError('NO_INPUT');
2001
- log('Core.Service.getPoll', input);
2002
- const poll = await ctx.app.model.Poll.findOne(getFilter(input)).exec();
2003
- if (!poll) throw new Error('Poll not found');
2004
- return poll as Poll;
2005
- }
2006
- async createPoll(input: RouterInput['createPoll'], ctx: RouterContext): Promise<RouterOutput['createPoll']> {
2007
- if (!input) throw new ARXError('NO_INPUT');
2008
- log('Core.Service.createPoll', input);
2009
- const poll = await ctx.app.model.Poll.create(input);
2010
- return poll as Poll;
2011
- }
2012
- async updatePoll(input: RouterInput['updatePoll'], ctx: RouterContext): Promise<RouterOutput['updatePoll']> {
2013
- if (!input) throw new ARXError('NO_INPUT');
2014
- log('Core.Service.updatePoll', input);
2015
- const updatedPoll = await ctx.app.model.Poll.findByIdAndUpdate(input.where.id.equals, { new: true }).exec();
2016
- if (!updatedPoll) throw new Error('Poll update failed');
2017
- return updatedPoll as Poll;
2018
- }
2019
- // Project Methods
2020
- async getProject(input: RouterInput['getProject'], ctx: RouterContext): Promise<RouterOutput['getProject']> {
2021
- if (!input) throw new ARXError('NO_INPUT');
2022
- log('Core.Service.getProject', input);
2023
- const project = await ctx.app.model.Project.findOne(getFilter(input)).exec();
2024
- if (!project) throw new Error('Project not found');
2025
- return project as Project;
2026
- }
2027
- async createProject(input: RouterInput['createProject'], ctx: RouterContext): Promise<RouterOutput['createProject']> {
2028
- if (!input) throw new ARXError('NO_INPUT');
2029
- log('Core.Service.createProject', input);
2030
- const project = await ctx.app.model.Project.create(input);
2031
- return project as Project;
2032
- }
2033
- async updateProject(input: RouterInput['updateProject'], ctx: RouterContext): Promise<RouterOutput['updateProject']> {
2034
- if (!input) throw new ARXError('NO_INPUT');
2035
- log('Core.Service.updateProject', input);
2036
- const updatedProject = await ctx.app.model.Project.findByIdAndUpdate(input.where.id.equals, { new: true })
2037
- .lean()
2038
- .exec();
2039
- if (!updatedProject) throw new Error('Project update failed');
2040
- return updatedProject as Project;
2041
- }
2042
- // Proposal Methods
2043
- async getProposal(input: RouterInput['getProposal'], ctx: RouterContext): Promise<RouterOutput['getProposal']> {
2044
- if (!input) throw new ARXError('NO_INPUT');
2045
- log('Core.Service.getProposal', input);
2046
- const proposal = await ctx.app.model.Proposal.findOne(getFilter(input)).exec();
2047
- if (!proposal) throw new Error('Proposal not found');
2048
- return proposal as Proposal;
2049
- }
2050
- async createProposal(
2051
- input: RouterInput['createProposal'],
2052
- ctx: RouterContext
2053
- ): Promise<RouterOutput['createProposal']> {
2054
- if (!input) throw new ARXError('NO_INPUT');
2055
- log('Core.Service.createProposal', input);
2056
- const proposal = await ctx.app.model.Proposal.create(input);
2057
- return proposal as Proposal;
2058
- }
2059
- async updateProposal(
2060
- input: RouterInput['updateProposal'],
2061
- ctx: RouterContext
2062
- ): Promise<RouterOutput['updateProposal']> {
2063
- if (!input) throw new ARXError('NO_INPUT');
2064
- log('Core.Service.updateProposal', input);
2065
- const updatedProposal = await ctx.app.model.Proposal.findByIdAndUpdate(input.where.id.equals, { new: true })
2066
- .lean()
2067
- .exec();
2068
- if (!updatedProposal) throw new Error('Proposal update failed');
2069
- return updatedProposal as Proposal;
2070
- }
2071
- // Quest Methods
2072
- async getQuest(input: RouterInput['getQuest'], ctx: RouterContext): Promise<RouterOutput['getQuest']> {
2073
- if (!input) throw new ARXError('NO_INPUT');
2074
- log('Core.Service.getQuest', input);
2075
- const quest = await ctx.app.model.Quest.findOne(getFilter(input)).exec();
2076
- if (!quest) throw new Error('Quest not found');
2077
- return quest as Quest;
2078
- }
2079
- async createQuest(input: RouterInput['createQuest'], ctx: RouterContext): Promise<RouterOutput['createQuest']> {
2080
- if (!input) throw new ARXError('NO_INPUT');
2081
- log('Core.Service.createQuest', input);
2082
- const quest = await ctx.app.model.Quest.create(input);
2083
- return quest as Quest;
2084
- }
2085
- async updateQuest(input: RouterInput['updateQuest'], ctx: RouterContext): Promise<RouterOutput['updateQuest']> {
2086
- if (!input) throw new ARXError('NO_INPUT');
2087
- log('Core.Service.updateQuest', input);
2088
- const updatedQuest = await ctx.app.model.Quest.findByIdAndUpdate(input.where.id.equals, { new: true })
2089
- .lean()
2090
- .exec();
2091
- if (!updatedQuest) throw new Error('Quest update failed');
2092
- return updatedQuest as Quest;
2093
- }
2094
- // Rating Methods
2095
- async getRating(input: RouterInput['getRating'], ctx: RouterContext): Promise<RouterOutput['getRating']> {
2096
- if (!input) throw new ARXError('NO_INPUT');
2097
- log('Core.Service.getRating', input);
2098
- const rating = await ctx.app.model.Rating.findOne(getFilter(input)).exec();
2099
- if (!rating) throw new Error('Rating not found');
2100
- return rating as Rating;
2101
- }
2102
- async createRating(input: RouterInput['createRating'], ctx: RouterContext): Promise<RouterOutput['createRating']> {
2103
- if (!input) throw new ARXError('NO_INPUT');
2104
- log('Core.Service.createRating', input);
2105
- const rating = await ctx.app.model.Rating.create(input);
2106
- return rating as Rating;
2107
- }
2108
- async updateRating(input: RouterInput['updateRating'], ctx: RouterContext): Promise<RouterOutput['updateRating']> {
2109
- if (!input) throw new ARXError('NO_INPUT');
2110
- log('Core.Service.updateRating', input);
2111
- const updatedRating = await ctx.app.model.Rating.findByIdAndUpdate(input.where.id.equals, { new: true })
2112
- .lean()
2113
- .exec();
2114
- if (!updatedRating) throw new Error('Rating update failed');
2115
- return updatedRating as Rating;
2116
- }
2117
- // Realm Methods
2118
- async getRealm(input: RouterInput['getRealm'], ctx: RouterContext): Promise<RouterOutput['getRealm']> {
2119
- if (!input) throw new ARXError('NO_INPUT');
2120
- log('Core.Service.getRealm', input);
2121
- const realm = await ctx.app.model.Realm.findOne(getFilter(input)).exec();
2122
- if (!realm) throw new Error('Realm not found');
2123
- return realm as Realm;
2124
- }
2125
- async getRealms(input: RouterInput['getRealms'], ctx: RouterContext): Promise<RouterOutput['getRealms']> {
2126
- log('Core.Service.getRealms', input);
2127
- const filter = getFilter(input);
2128
- filter.status = 'Online';
2129
- let realms: Realm[] = await ctx.app.model.Realm.find(filter).exec();
2130
- console.log('getRealms', realms);
2131
- realms = [
2132
- {
2133
- status: 'Online',
2134
- clientCount: 1,
2135
- regionCode: 'EU',
2136
- endpoint: 'evolution-realm-1.arken.gg',
2137
- gameId: '673996aec43266df5f966da6',
2138
- realmShards: [
2139
- {
2140
- status: 'Online',
2141
- clientCount: 1,
2142
- endpoint: 'evolution-realm-shard-1.arken.gg',
2143
- },
2144
- ],
2145
- },
2146
- ];
2147
- return realms;
2148
- }
2149
- async createRealm(input: RouterInput['createRealm'], ctx: RouterContext): Promise<RouterOutput['createRealm']> {
2150
- if (!input) throw new ARXError('NO_INPUT');
2151
- log('Core.Service.createRealm', input);
2152
- const realm = await ctx.app.model.Realm.create(input);
2153
- return realm as Realm;
2154
- }
2155
- async updateRealm(input: RouterInput['updateRealm'], ctx: RouterContext): Promise<RouterOutput['updateRealm']> {
2156
- if (!input) throw new ARXError('NO_INPUT');
2157
- log('Core.Service.updateRealm', input);
2158
- // const data = {};
2159
- // if (!this.realms[input.data.realmId]) this.realms[input.data.realmId] = {};
2160
- // const realm: Arken.Core.Types.Realm = this.realms[input.data.realmId];
2161
- // realm.status = input.data.status;
2162
- // realm.clientCount = input.data.clientCount;
2163
- // realm.regionCode = input.data.regionCode;
2164
- // realm.realmShards = input.data.realmShards;
2165
- const updatedRealm = await ctx.app.model.Realm.findByIdAndUpdate(input.where.id.equals, { new: true })
2166
- .lean()
2167
- .exec();
2168
- if (!updatedRealm) throw new Error('Realm update failed');
2169
- return updatedRealm as Realm;
2170
- }
2171
- // RealmEvent Methods
2172
- async getRealmEvent(input: RouterInput['getRealmEvent'], ctx: RouterContext): Promise<RouterOutput['getRealmEvent']> {
2173
- if (!input) throw new ARXError('NO_INPUT');
2174
- log('Core.Service.getRealmEvent', input);
2175
- const realmEvent = await ctx.app.model.RealmEvent.findOne(getFilter(input)).exec();
2176
- if (!realmEvent) throw new Error('RealmEvent not found');
2177
- return realmEvent as RealmEvent;
2178
- }
2179
- async getRealmEvents(
2180
- input: RouterInput['getRealmEvents'],
2181
- ctx: RouterContext
2182
- ): Promise<RouterOutput['getRealmEvents']> {
2183
- log('Core.Service.getRealmEvents', input);
2184
- const filter = getFilter(input);
2185
- filter.status = 'Online';
2186
- let realmEvents: RealmEvent[] = await ctx.app.model.RealmEvent.find(filter).exec();
2187
- console.log('getRealmEvents', realmEvents);
2188
- return realmEvents;
2189
- }
2190
- async createRealmEvent(
2191
- input: RouterInput['createRealmEvent'],
2192
- ctx: RouterContext
2193
- ): Promise<RouterOutput['createRealmEvent']> {
2194
- if (!input) throw new ARXError('NO_INPUT');
2195
- log('Core.Service.createRealmEvent', input);
2196
- const realmEvent = await ctx.app.model.RealmEvent.create(input);
2197
- return realmEvent as RealmEvent;
2198
- }
2199
- async updateRealmEvent(
2200
- input: RouterInput['updateRealmEvent'],
2201
- ctx: RouterContext
2202
- ): Promise<RouterOutput['updateRealmEvent']> {
2203
- if (!input) throw new ARXError('NO_INPUT');
2204
- log('Core.Service.updateRealmEvent', input);
2205
- // const data = {};
2206
- // if (!this.realms[input.data.realmId]) this.realms[input.data.realmId] = {};
2207
- // const realm: Arken.Core.Types.RealmEvent = this.realms[input.data.realmId];
2208
- // realm.status = input.data.status;
2209
- // realm.clientCount = input.data.clientCount;
2210
- // realm.regionCode = input.data.regionCode;
2211
- // realm.realmShards = input.data.realmShards;
2212
- const updatedRealmEvent = await ctx.app.model.RealmEvent.findByIdAndUpdate(input.where.id.equals, { new: true })
2213
- .lean()
2214
- .exec();
2215
- if (!updatedRealmEvent) throw new Error('RealmEvent update failed');
2216
- return updatedRealmEvent as RealmEvent;
2217
- }
2218
- // Revision Methods
2219
- async getRevision(input: RouterInput['getRevision'], ctx: RouterContext): Promise<RouterOutput['getRevision']> {
2220
- if (!input) throw new ARXError('NO_INPUT');
2221
- log('Core.Service.getRevision', input);
2222
- const revision = await ctx.app.model.Revision.findOne(getFilter(input)).exec();
2223
- if (!revision) throw new Error('Revision not found');
2224
- return revision as Revision;
2225
- }
2226
- async createRevision(
2227
- input: RouterInput['createRevision'],
2228
- ctx: RouterContext
2229
- ): Promise<RouterOutput['createRevision']> {
2230
- if (!input) throw new ARXError('NO_INPUT');
2231
- log('Core.Service.createRevision', input);
2232
- const revision = await ctx.app.model.Revision.create(input);
2233
- return revision as Revision;
2234
- }
2235
- async updateRevision(
2236
- input: RouterInput['updateRevision'],
2237
- ctx: RouterContext
2238
- ): Promise<RouterOutput['updateRevision']> {
2239
- if (!input) throw new ARXError('NO_INPUT');
2240
- log('Core.Service.updateRevision', input);
2241
- const updatedRevision = await ctx.app.model.Revision.findByIdAndUpdate(input.where.id.equals, {
2242
- new: true,
2243
- })
2244
- .lean()
2245
- .exec();
2246
- if (!updatedRevision) throw new Error('Revision update failed');
2247
- return updatedRevision as Revision;
2248
- }
2249
- // Referral Methods
2250
- async getReferral(input: RouterInput['getReferral'], ctx: RouterContext): Promise<RouterOutput['getReferral']> {
2251
- if (!input) throw new ARXError('NO_INPUT');
2252
- log('Core.Service.getReferral', input);
2253
- const referral = await ctx.app.model.Referral.findOne(getFilter(input)).exec();
2254
- if (!referral) throw new Error('Referral not found');
2255
- return referral as Referral;
2256
- }
2257
- async createReferral(
2258
- input: RouterInput['createReferral'],
2259
- ctx: RouterContext
2260
- ): Promise<RouterOutput['createReferral']> {
2261
- if (!input) throw new ARXError('NO_INPUT');
2262
- log('Core.Service.createReferral', input);
2263
- const referral = await ctx.app.model.Referral.create(input);
2264
- return referral as Referral;
2265
- }
2266
- async updateReferral(
2267
- input: RouterInput['updateReferral'],
2268
- ctx: RouterContext
2269
- ): Promise<RouterOutput['updateReferral']> {
2270
- if (!input) throw new ARXError('NO_INPUT');
2271
- log('Core.Service.updateReferral', input);
2272
- const updatedReferral = await ctx.app.model.Referral.findByIdAndUpdate(input.where.id.equals, { new: true })
2273
- .lean()
2274
- .exec();
2275
- if (!updatedReferral) throw new Error('Referral update failed');
2276
- return updatedReferral as Referral;
2277
- }
2278
- // Review Methods
2279
- async getReview(input: RouterInput['getReview'], ctx: RouterContext): Promise<RouterOutput['getReview']> {
2280
- if (!input) throw new ARXError('NO_INPUT');
2281
- log('Core.Service.getReview', input);
2282
- const review = await ctx.app.model.Review.findOne(getFilter(input)).exec();
2283
- if (!review) throw new Error('Review not found');
2284
- return review as Review;
2285
- }
2286
- async createReview(input: RouterInput['createReview'], ctx: RouterContext): Promise<RouterOutput['createReview']> {
2287
- if (!input) throw new ARXError('NO_INPUT');
2288
- log('Core.Service.createReview', input);
2289
- const review = await ctx.app.model.Review.create(input);
2290
- return review as Review;
2291
- }
2292
- async updateReview(input: RouterInput['updateReview'], ctx: RouterContext): Promise<RouterOutput['updateReview']> {
2293
- if (!input) throw new ARXError('NO_INPUT');
2294
- log('Core.Service.updateReview', input);
2295
- const updatedReview = await ctx.app.model.Review.findByIdAndUpdate(input.where.id.equals, { new: true })
2296
- .lean()
2297
- .exec();
2298
- if (!updatedReview) throw new Error('Review update failed');
2299
- return updatedReview as Review;
2300
- }
2301
- // Role Methods
2302
- async getRole(input: RouterInput['getRole'], ctx: RouterContext): Promise<RouterOutput['getRole']> {
2303
- if (!input) throw new ARXError('NO_INPUT');
2304
- log('Core.Service.getRole', input);
2305
- const role = await ctx.app.model.Role.findOne(getFilter(input)).exec();
2306
- if (!role) throw new Error('Role not found');
2307
- return role as Role;
2308
- }
2309
- async createRole(input: RouterInput['createRole'], ctx: RouterContext): Promise<RouterOutput['createRole']> {
2310
- if (!input) throw new ARXError('NO_INPUT');
2311
- log('Core.Service.createRole', input);
2312
- const role = await ctx.app.model.Role.create(input);
2313
- return role as Role;
2314
- }
2315
- async updateRole(input: RouterInput['updateRole'], ctx: RouterContext): Promise<RouterOutput['updateRole']> {
2316
- if (!input) throw new ARXError('NO_INPUT');
2317
- log('Core.Service.updateRole', input);
2318
- const updatedRole = await ctx.app.model.Role.findByIdAndUpdate(input.where.id.equals, { new: true }).exec();
2319
- if (!updatedRole) throw new Error('Role update failed');
2320
- return updatedRole as Role;
2321
- }
2322
- // Season Methods
2323
- async getSeason(input: RouterInput['getSeason'], ctx: RouterContext): Promise<RouterOutput['getSeason']> {
2324
- if (!input) throw new ARXError('NO_INPUT');
2325
- log('Core.Service.getSeason', input);
2326
- const season = await ctx.app.model.Season.findOne(getFilter(input)).exec();
2327
- if (!season) throw new Error('Season not found');
2328
- return season as Season;
2329
- }
2330
- async createSeason(input: RouterInput['createSeason'], ctx: RouterContext): Promise<RouterOutput['createSeason']> {
2331
- if (!input) throw new ARXError('NO_INPUT');
2332
- log('Core.Service.createSeason', input);
2333
- const season = await ctx.app.model.Season.create(input);
2334
- return season as Season;
2335
- }
2336
- async updateSeason(input: RouterInput['updateSeason'], ctx: RouterContext): Promise<RouterOutput['updateSeason']> {
2337
- if (!input) throw new ARXError('NO_INPUT');
2338
- log('Core.Service.updateSeason', input);
2339
- const updatedSeason = await ctx.app.model.Season.findByIdAndUpdate(input.where.id.equals, { new: true })
2340
- .lean()
2341
- .exec();
2342
- if (!updatedSeason) throw new Error('Season update failed');
2343
- return updatedSeason as Season;
2344
- }
2345
- // RealmShard Methods
2346
- async getRealmShard(input: RouterInput['getRealmShard'], ctx: RouterContext): Promise<RouterOutput['getRealmShard']> {
2347
- if (!input) throw new ARXError('NO_INPUT');
2348
- log('Core.Service.getRealmShard', input);
2349
- const server = await ctx.app.model.RealmShard.findOne(getFilter(input)).exec();
2350
- if (!server) throw new Error('RealmShard not found');
2351
- return server as RealmShard;
2352
- }
2353
- async getRealmShards(
2354
- input: RouterInput['getRealmShards'],
2355
- ctx: RouterContext
2356
- ): Promise<RouterOutput['getRealmShards']> {
2357
- log('Core.Service.getRealmShards', input);
2358
- const filter = getFilter(input);
2359
- filter.status = 'Active';
2360
- const servers = await ctx.app.model.RealmShard.find(filter).exec();
2361
- return servers as RealmShard[];
2362
- }
2363
- async createRealmShard(
2364
- input: RouterInput['createRealmShard'],
2365
- ctx: RouterContext
2366
- ): Promise<RouterOutput['createRealmShard']> {
2367
- if (!input) throw new ARXError('NO_INPUT');
2368
- log('Core.Service.createRealmShard', input);
2369
- const server = await ctx.app.model.RealmShard.create(input);
2370
- return server as RealmShard;
2371
- }
2372
- async updateRealmShard(
2373
- input: RouterInput['updateRealmShard'],
2374
- ctx: RouterContext
2375
- ): Promise<RouterOutput['updateRealmShard']> {
2376
- if (!input) throw new ARXError('NO_INPUT');
2377
- log('Core.Service.updateRealmShard', input);
2378
- const updatedRealmShard = await ctx.app.model.RealmShard.findByIdAndUpdate(input.where.id.equals, { new: true })
2379
- .lean()
2380
- .exec();
2381
- if (!updatedRealmShard) throw new Error('RealmShard update failed');
2382
- return updatedRealmShard as RealmShard;
2383
- }
2384
- // Session Methods
2385
- async getSession(input: RouterInput['getSession'], ctx: RouterContext): Promise<RouterOutput['getSession']> {
2386
- if (!input) throw new ARXError('NO_INPUT');
2387
- log('Core.Service.getSession', input);
2388
- const session = await ctx.app.model.Session.findOne(getFilter(input)).exec();
2389
- if (!session) throw new Error('Session not found');
2390
- return session as Session;
2391
- }
2392
- async createSession(input: RouterInput['createSession'], ctx: RouterContext): Promise<RouterOutput['createSession']> {
2393
- if (!input) throw new ARXError('NO_INPUT');
2394
- log('Core.Service.createSession', input);
2395
- const session = await ctx.app.model.Session.create(input);
2396
- return session as Session;
2397
- }
2398
- async updateSession(input: RouterInput['updateSession'], ctx: RouterContext): Promise<RouterOutput['updateSession']> {
2399
- if (!input) throw new ARXError('NO_INPUT');
2400
- log('Core.Service.updateSession', input);
2401
- const updatedSession = await ctx.app.model.Session.findByIdAndUpdate(input.where.id.equals, { new: true })
2402
- .lean()
2403
- .exec();
2404
- if (!updatedSession) throw new Error('Session update failed');
2405
- return updatedSession as Session;
2406
- }
2407
- // SolarSystem Methods
2408
- async getSolarSystem(
2409
- input: RouterInput['getSolarSystem'],
2410
- ctx: RouterContext
2411
- ): Promise<RouterOutput['getSolarSystem']> {
2412
- if (!input) throw new ARXError('NO_INPUT');
2413
- log('Core.Service.getSolarSystem', input);
2414
- const solarSystem = await ctx.app.model.SolarSystem.findOne(getFilter(input)).exec();
2415
- if (!solarSystem) throw new Error('SolarSystem not found');
2416
- return solarSystem as SolarSystem;
2417
- }
2418
- async createSolarSystem(
2419
- input: RouterInput['createSolarSystem'],
2420
- ctx: RouterContext
2421
- ): Promise<RouterOutput['createSolarSystem']> {
2422
- if (!input) throw new ARXError('NO_INPUT');
2423
- log('Core.Service.createSolarSystem', input);
2424
- const solarSystem = await ctx.app.model.SolarSystem.create(input);
2425
- return solarSystem as SolarSystem;
2426
- }
2427
- async updateSolarSystem(
2428
- input: RouterInput['updateSolarSystem'],
2429
- ctx: RouterContext
2430
- ): Promise<RouterOutput['updateSolarSystem']> {
2431
- if (!input) throw new ARXError('NO_INPUT');
2432
- log('Core.Service.updateSolarSystem', input);
2433
- const updatedSolarSystem = await ctx.app.model.SolarSystem.findByIdAndUpdate(input.where.id.equals, {
2434
- new: true,
2435
- })
2436
- .lean()
2437
- .exec();
2438
- if (!updatedSolarSystem) throw new Error('SolarSystem update failed');
2439
- return updatedSolarSystem as SolarSystem;
2440
- }
2441
- // Star Methods
2442
- async getStar(input: RouterInput['getStar'], ctx: RouterContext): Promise<RouterOutput['getStar']> {
2443
- if (!input) throw new ARXError('NO_INPUT');
2444
- log('Core.Service.getStar', input);
2445
- const star = await ctx.app.model.Star.findOne(getFilter(input)).exec();
2446
- if (!star) throw new Error('Star not found');
2447
- return star as Star;
2448
- }
2449
- async createStar(input: RouterInput['createStar'], ctx: RouterContext): Promise<RouterOutput['createStar']> {
2450
- if (!input) throw new ARXError('NO_INPUT');
2451
- log('Core.Service.createStar', input);
2452
- const star = await ctx.app.model.Star.create(input);
2453
- return star as Star;
2454
- }
2455
- async updateStar(input: RouterInput['updateStar'], ctx: RouterContext): Promise<RouterOutput['updateStar']> {
2456
- if (!input) throw new ARXError('NO_INPUT');
2457
- log('Core.Service.updateStar', input);
2458
- const updatedStar = await ctx.app.model.Star.findByIdAndUpdate(input.where.id.equals, { new: true }).exec();
2459
- if (!updatedStar) throw new Error('Star update failed');
2460
- return updatedStar as Star;
2461
- }
2462
- // Stash Methods
2463
- async getStash(input: RouterInput['getStash'], ctx: RouterContext): Promise<RouterOutput['getStash']> {
2464
- if (!input) throw new ARXError('NO_INPUT');
2465
- log('Core.Service.getStash', input);
2466
- const stash = await ctx.app.model.Stash.findOne(getFilter(input)).exec();
2467
- if (!stash) throw new Error('Stash not found');
2468
- return stash as Stash;
2469
- }
2470
- async createStash(input: RouterInput['createStash'], ctx: RouterContext): Promise<RouterOutput['createStash']> {
2471
- if (!input) throw new ARXError('NO_INPUT');
2472
- log('Core.Service.createStash', input);
2473
- const stash = await ctx.app.model.Stash.create(input);
2474
- return stash as Stash;
2475
- }
2476
- async updateStash(input: RouterInput['updateStash'], ctx: RouterContext): Promise<RouterOutput['updateStash']> {
2477
- if (!input) throw new ARXError('NO_INPUT');
2478
- log('Core.Service.updateStash', input);
2479
- const updatedStash = await ctx.app.model.Stash.findByIdAndUpdate(input.where.id.equals, { new: true })
2480
- .lean()
2481
- .exec();
2482
- if (!updatedStash) throw new Error('Stash update failed');
2483
- return updatedStash as Stash;
2484
- }
2485
- // Stock Methods
2486
- async getStock(input: RouterInput['getStock'], ctx: RouterContext): Promise<RouterOutput['getStock']> {
2487
- if (!input) throw new ARXError('NO_INPUT');
2488
- log('Core.Service.getStock', input);
2489
- const stock = await ctx.app.model.Stock.findOne(getFilter(input)).exec();
2490
- if (!stock) throw new Error('Stock not found');
2491
- return stock as Stock;
2492
- }
2493
- async createStock(input: RouterInput['createStock'], ctx: RouterContext): Promise<RouterOutput['createStock']> {
2494
- if (!input) throw new ARXError('NO_INPUT');
2495
- log('Core.Service.createStock', input);
2496
- const stock = await ctx.app.model.Stock.create(input);
2497
- return stock as Stock;
2498
- }
2499
- async updateStock(input: RouterInput['updateStock'], ctx: RouterContext): Promise<RouterOutput['updateStock']> {
2500
- if (!input) throw new ARXError('NO_INPUT');
2501
- log('Core.Service.updateStock', input);
2502
- const updatedStock = await ctx.app.model.Stock.findByIdAndUpdate(input.where.id.equals, { new: true })
2503
- .lean()
2504
- .exec();
2505
- if (!updatedStock) throw new Error('Stock update failed');
2506
- return updatedStock as Stock;
2507
- } // Suggestion Methods
2508
- async getSuggestion(input: RouterInput['getSuggestion'], ctx: RouterContext): Promise<RouterOutput['getSuggestion']> {
2509
- if (!input) throw new ARXError('NO_INPUT');
2510
- log('Core.Service.getSuggestion', input);
2511
- const suggestion = await ctx.app.model.Suggestion.findOne(getFilter(input)).exec();
2512
- if (!suggestion) throw new Error('Suggestion not found');
2513
- return suggestion as Suggestion;
2514
- }
2515
- async createSuggestion(
2516
- input: RouterInput['createSuggestion'],
2517
- ctx: RouterContext
2518
- ): Promise<RouterOutput['createSuggestion']> {
2519
- if (!input) throw new ARXError('NO_INPUT');
2520
- log('Core.Service.createSuggestion', input);
2521
- const suggestion = await ctx.app.model.Suggestion.create(input);
2522
- return suggestion as Suggestion;
2523
- }
2524
- async updateSuggestion(
2525
- input: RouterInput['updateSuggestion'],
2526
- ctx: RouterContext
2527
- ): Promise<RouterOutput['updateSuggestion']> {
2528
- if (!input) throw new ARXError('NO_INPUT');
2529
- log('Core.Service.updateSuggestion', input);
2530
- const updatedSuggestion = await ctx.app.model.Suggestion.findByIdAndUpdate(input.where.id.equals, {
2531
- new: true,
2532
- })
2533
- .lean()
2534
- .exec();
2535
- if (!updatedSuggestion) throw new Error('Suggestion update failed');
2536
- return updatedSuggestion as Suggestion;
2537
- }
2538
- // Tag Methods
2539
- async getTag(input: RouterInput['getTag'], ctx: RouterContext): Promise<RouterOutput['getTag']> {
2540
- if (!input) throw new ARXError('NO_INPUT');
2541
- log('Core.Service.getTag', input);
2542
- const tag = await ctx.app.model.Tag.findOne(getFilter(input)).exec();
2543
- if (!tag) throw new Error('Tag not found');
2544
- return tag as Tag;
2545
- }
2546
- async createTag(input: RouterInput['createTag'], ctx: RouterContext): Promise<RouterOutput['createTag']> {
2547
- if (!input) throw new ARXError('NO_INPUT');
2548
- log('Core.Service.createTag', input);
2549
- const tag = await ctx.app.model.Tag.create(input);
2550
- return tag as Tag;
2551
- }
2552
- async updateTag(input: RouterInput['updateTag'], ctx: RouterContext): Promise<RouterOutput['updateTag']> {
2553
- if (!input) throw new ARXError('NO_INPUT');
2554
- log('Core.Service.updateTag', input);
2555
- const updatedTag = await ctx.app.model.Tag.findByIdAndUpdate(input.where.id.equals, { new: true }).exec();
2556
- if (!updatedTag) throw new Error('Tag update failed');
2557
- return updatedTag as Tag;
2558
- }
2559
- // Team Methods
2560
- async getTeam(input: RouterInput['getTeam'], ctx: RouterContext): Promise<RouterOutput['getTeam']> {
2561
- if (!input) throw new ARXError('NO_INPUT');
2562
- log('Core.Service.getTeam', input);
2563
- const filter = getFilter(input);
2564
- const team = await ctx.app.model.Team.findOne(filter).exec();
2565
- if (!team) throw new Error('Team not found');
2566
- return team as Team;
2567
- }
2568
- async getTeams(input: RouterInput['getTeams'], ctx: RouterContext): Promise<RouterOutput['getTeams']> {
2569
- if (!input) throw new ARXError('NO_INPUT');
2570
- log('Core.Service.getTeams', input);
2571
- const filter = getFilter(input);
2572
- const teams = await ctx.app.model.Team.find(filter)
2573
- .skip(input.skip || 0)
2574
- .limit(input.limit || 10)
2575
- .exec();
2576
- return teams as Team[];
2577
- }
2578
- async createTeam(input: RouterInput['createTeam'], ctx: RouterContext): Promise<RouterOutput['createTeam']> {
2579
- if (!input) throw new ARXError('NO_INPUT');
2580
- log('Core.Service.createTeam', input);
2581
- const team = await ctx.app.model.Team.create(input);
2582
- return team as Team;
2583
- }
2584
- async updateTeam(input: RouterInput['updateTeam'], ctx: RouterContext): Promise<RouterOutput['updateTeam']> {
2585
- if (!input) throw new ARXError('NO_INPUT');
2586
- log('Core.Service.updateTeam', input);
2587
- const updatedTeam = await ctx.app.model.Team.findByIdAndUpdate(input.where.id.equals, { new: true }).exec();
2588
- if (!updatedTeam) throw new Error('Team update failed');
2589
- return updatedTeam as Team;
2590
- }
2591
- // Tournament Methods
2592
- async getTournament(input: RouterInput['getTournament'], ctx: RouterContext): Promise<RouterOutput['getTournament']> {
2593
- if (!input) throw new ARXError('NO_INPUT');
2594
- log('Core.Service.getTournament', input);
2595
- const tournament = await ctx.app.model.Tournament.findOne(getFilter(input)).exec();
2596
- if (!tournament) throw new Error('Tournament not found');
2597
- return tournament as Tournament;
2598
- }
2599
- async createTournament(
2600
- input: RouterInput['createTournament'],
2601
- ctx: RouterContext
2602
- ): Promise<RouterOutput['createTournament']> {
2603
- if (!input) throw new ARXError('NO_INPUT');
2604
- log('Core.Service.createTournament', input);
2605
- const tournament = await ctx.app.model.Tournament.create(input);
2606
- return tournament as Tournament;
2607
- }
2608
- async updateTournament(
2609
- input: RouterInput['updateTournament'],
2610
- ctx: RouterContext
2611
- ): Promise<RouterOutput['updateTournament']> {
2612
- if (!input) throw new ARXError('NO_INPUT');
2613
- log('Core.Service.updateTournament', input);
2614
- const updatedTournament = await ctx.app.model.Tournament.findByIdAndUpdate(input.where.id.equals, {
2615
- new: true,
2616
- })
2617
- .lean()
2618
- .exec();
2619
- if (!updatedTournament) throw new Error('Tournament update failed');
2620
- return updatedTournament as Tournament;
2621
- }
2622
- // Trade Methods
2623
- async getTrade(input: RouterInput['getTrade'], ctx: RouterContext): Promise<RouterOutput['getTrade']> {
2624
- if (!input) throw new ARXError('NO_INPUT');
2625
- log('Core.Service.getTrade', input);
2626
- const trade = await ctx.app.model.Trade.findOne(getFilter(input)).exec();
2627
- if (!trade) throw new Error('Trade not found');
2628
- return trade as Trade;
2629
- }
2630
- async getTrades(input: RouterInput['getTrades'], ctx: RouterContext): Promise<RouterOutput['getTrades']> {
2631
- if (!input) throw new ARXError('NO_INPUT');
2632
- log('Core.Service.getTrades', input);
2633
- const trade = await ctx.app.model.Trade.find().limit(10).exec();
2634
- return trade as Trade[];
2635
- }
2636
- async createTrade(input: RouterInput['createTrade'], ctx: RouterContext): Promise<RouterOutput['createTrade']> {
2637
- if (!input) throw new ARXError('NO_INPUT');
2638
- log('Core.Service.createTrade', input);
2639
- const trade = await ctx.app.model.Trade.create(input);
2640
- return trade as Trade;
2641
- }
2642
- async updateTrade(input: RouterInput['updateTrade'], ctx: RouterContext): Promise<RouterOutput['updateTrade']> {
2643
- if (!input) throw new ARXError('NO_INPUT');
2644
- log('Core.Service.updateTrade', input);
2645
- const updatedTrade = await ctx.app.model.Trade.findByIdAndUpdate(input.where.id.equals, { new: true })
2646
- .lean()
2647
- .exec();
2648
- if (!updatedTrade) throw new Error('Trade update failed');
2649
- return updatedTrade as Trade;
2650
- }
2651
- // Universe Methods
2652
- async getUniverse(input: RouterInput['getUniverse'], ctx: RouterContext): Promise<RouterOutput['getUniverse']> {
2653
- if (!input) throw new ARXError('NO_INPUT');
2654
- log('Core.Service.getUniverse', input);
2655
- const universe = await ctx.app.model.Universe.findOne(getFilter(input)).exec();
2656
- if (!universe) throw new Error('Universe not found');
2657
- return universe as Universe;
2658
- }
2659
- async createUniverse(
2660
- input: RouterInput['createUniverse'],
2661
- ctx: RouterContext
2662
- ): Promise<RouterOutput['createUniverse']> {
2663
- if (!input) throw new ARXError('NO_INPUT');
2664
- log('Core.Service.createUniverse', input);
2665
- const universe = await ctx.app.model.Universe.create(input);
2666
- return universe as Universe;
2667
- }
2668
- async updateUniverse(
2669
- input: RouterInput['updateUniverse'],
2670
- ctx: RouterContext
2671
- ): Promise<RouterOutput['updateUniverse']> {
2672
- if (!input) throw new ARXError('NO_INPUT');
2673
- log('Core.Service.updateUniverse', input);
2674
- const updatedUniverse = await ctx.app.model.Universe.findByIdAndUpdate(input.where.id.equals, { new: true })
2675
- .lean()
2676
- .exec();
2677
- if (!updatedUniverse) throw new Error('Universe update failed');
2678
- return updatedUniverse as Universe;
2679
- }
2680
- // Validator Methods
2681
- async getValidator(input: RouterInput['getValidator'], ctx: RouterContext): Promise<RouterOutput['getValidator']> {
2682
- if (!input) throw new ARXError('NO_INPUT');
2683
- log('Core.Service.getValidator', input);
2684
- const validator = await ctx.app.model.Validator.findOne(getFilter(input)).exec();
2685
- if (!validator) throw new Error('Validator not found');
2686
- return validator as Validator;
2687
- }
2688
- async createValidator(
2689
- input: RouterInput['createValidator'],
2690
- ctx: RouterContext
2691
- ): Promise<RouterOutput['createValidator']> {
2692
- if (!input) throw new ARXError('NO_INPUT');
2693
- log('Core.Service.createValidator', input);
2694
- const validator = await ctx.app.model.Validator.create(input);
2695
- return validator as Validator;
2696
- }
2697
- async updateValidator(
2698
- input: RouterInput['updateValidator'],
2699
- ctx: RouterContext
2700
- ): Promise<RouterOutput['updateValidator']> {
2701
- if (!input) throw new ARXError('NO_INPUT');
2702
- log('Core.Service.updateValidator', input);
2703
- const updatedValidator = await ctx.app.model.Validator.findByIdAndUpdate(input.where.id.equals, {
2704
- new: true,
2705
- })
2706
- .lean()
2707
- .exec();
2708
- if (!updatedValidator) throw new Error('Validator update failed');
2709
- return updatedValidator as Validator;
2710
- }
2711
- // Vote Methods
2712
- async getVote(input: RouterInput['getVote'], ctx: RouterContext): Promise<RouterOutput['getVote']> {
2713
- if (!input) throw new ARXError('NO_INPUT');
2714
- log('Core.Service.getVote', input);
2715
- const vote = await ctx.app.model.Vote.findOne(getFilter(input)).exec();
2716
- if (!vote) throw new Error('Vote not found');
2717
- return vote as Vote;
2718
- }
2719
- async createVote(input: RouterInput['createVote'], ctx: RouterContext): Promise<RouterOutput['createVote']> {
2720
- if (!input) throw new ARXError('NO_INPUT');
2721
- log('Core.Service.createVote', input);
2722
- const vote = await ctx.app.model.Vote.create(input);
2723
- return vote as Vote;
2724
- }
2725
- async updateVote(input: RouterInput['updateVote'], ctx: RouterContext): Promise<RouterOutput['updateVote']> {
2726
- if (!input) throw new ARXError('NO_INPUT');
2727
- log('Core.Service.updateVote', input);
2728
- const updatedVote = await ctx.app.model.Vote.findByIdAndUpdate(input.where.id.equals, { new: true }).exec();
2729
- if (!updatedVote) throw new Error('Vote update failed');
2730
- return updatedVote as Vote;
2731
- }
2732
- // WorldEvent Methods
2733
- async getWorldEvent(input: RouterInput['getWorldEvent'], ctx: RouterContext): Promise<RouterOutput['getWorldEvent']> {
2734
- if (!input) throw new ARXError('NO_INPUT');
2735
- log('Core.Service.getWorldEvent', input);
2736
- const worldEvent = await ctx.app.model.WorldEvent.findOne(getFilter(input)).exec();
2737
- if (!worldEvent) throw new Error('WorldEvent not found');
2738
- return worldEvent as WorldEvent;
2739
- }
2740
- async createWorldEvent(
2741
- input: RouterInput['createWorldEvent'],
2742
- ctx: RouterContext
2743
- ): Promise<RouterOutput['createWorldEvent']> {
2744
- if (!input) throw new ARXError('NO_INPUT');
2745
- log('Core.Service.createWorldEvent', input);
2746
- const worldEvent = await ctx.app.model.WorldEvent.create(input);
2747
- return worldEvent as WorldEvent;
2748
- }
2749
- async updateWorldEvent(
2750
- input: RouterInput['updateWorldEvent'],
2751
- ctx: RouterContext
2752
- ): Promise<RouterOutput['updateWorldEvent']> {
2753
- if (!input) throw new ARXError('NO_INPUT');
2754
- log('Core.Service.updateWorldEvent', input);
2755
- const updatedWorldEvent = await ctx.app.model.WorldEvent.findByIdAndUpdate(input.where.id.equals, {
2756
- new: true,
2757
- })
2758
- .lean()
2759
- .exec();
2760
- if (!updatedWorldEvent) throw new Error('WorldEvent update failed');
2761
- return updatedWorldEvent as WorldEvent;
2762
- }
2763
- // WorldRecord Methods
2764
- async getWorldRecord(
2765
- input: RouterInput['getWorldRecord'],
2766
- ctx: RouterContext
2767
- ): Promise<RouterOutput['getWorldRecord']> {
2768
- if (!input) throw new ARXError('NO_INPUT');
2769
- log('Core.Service.getWorldRecord', input);
2770
- const worldRecord = await ctx.app.model.WorldRecord.findOne(getFilter(input)).exec();
2771
- if (!worldRecord) throw new Error('WorldRecord not found');
2772
- return worldRecord as WorldRecord;
2773
- }
2774
- async createWorldRecord(
2775
- input: RouterInput['createWorldRecord'],
2776
- ctx: RouterContext
2777
- ): Promise<RouterOutput['createWorldRecord']> {
2778
- if (!input) throw new ARXError('NO_INPUT');
2779
- log('Core.Service.createWorldRecord', input);
2780
- const worldRecord = await ctx.app.model.WorldRecord.create(input);
2781
- return worldRecord as WorldRecord;
2782
- }
2783
- async updateWorldRecord(
2784
- input: RouterInput['updateWorldRecord'],
2785
- ctx: RouterContext
2786
- ): Promise<RouterOutput['updateWorldRecord']> {
2787
- if (!input) throw new ARXError('NO_INPUT');
2788
- log('Core.Service.updateWorldRecord', input);
2789
- const updatedWorldRecord = await ctx.app.model.WorldRecord.findByIdAndUpdate(input.where.id.equals, {
2790
- new: true,
2791
- })
2792
- .lean()
2793
- .exec();
2794
- if (!updatedWorldRecord) throw new Error('WorldRecord update failed');
2795
- return updatedWorldRecord as WorldRecord;
2796
- }
2797
- // Get Bounty
2798
- async getBounty(input: RouterInput['getBounty'], ctx: RouterContext): Promise<RouterOutput['getBounty']> {
2799
- if (!input) throw new ARXError('NO_INPUT');
2800
- log('Core.Service.getBounty', input);
2801
- const bounty = await ctx.app.model.Bounty.findOne(getFilter(input)).exec();
2802
- if (!bounty) throw new Error('Bounty not found');
2803
- return bounty as Bounty;
2804
- }
2805
- // Create Bounty
2806
- async createBounty(input: RouterInput['createBounty'], ctx: RouterContext): Promise<RouterOutput['createBounty']> {
2807
- if (!input) throw new ARXError('NO_INPUT');
2808
- log('Core.Service.createBounty', input);
2809
- const bounty = await ctx.app.model.Bounty.create(input);
2810
- return bounty as Bounty;
2811
- }
2812
- // Update Bounty
2813
- async updateBounty(input: RouterInput['updateBounty'], ctx: RouterContext): Promise<RouterOutput['updateBounty']> {
2814
- if (!input) throw new ARXError('NO_INPUT');
2815
- log('Core.Service.updateBounty', input);
2816
- const updatedBounty = await ctx.app.model.Bounty.findByIdAndUpdate(input.where.id.equals, { new: true })
2817
- .lean()
2818
- .exec();
2819
- if (!updatedBounty) throw new Error('Bounty update failed');
2820
- return updatedBounty as Bounty;
2821
- }
2822
- }