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