dgc-core 2.0.1 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,6 @@ export declare enum UserCollectorType {
2
2
  'Non-member' = -1,
3
3
  Free = 2,
4
4
  Rookie = 1,
5
- Collector = 0,
6
- Elite = 3
5
+ Collector = 3,
6
+ Elite = 0
7
7
  }
@@ -6,6 +6,6 @@ var UserCollectorType;
6
6
  UserCollectorType[UserCollectorType["Non-member"] = -1] = "Non-member";
7
7
  UserCollectorType[UserCollectorType["Free"] = 2] = "Free";
8
8
  UserCollectorType[UserCollectorType["Rookie"] = 1] = "Rookie";
9
- UserCollectorType[UserCollectorType["Collector"] = 0] = "Collector";
10
- UserCollectorType[UserCollectorType["Elite"] = 3] = "Elite";
9
+ UserCollectorType[UserCollectorType["Collector"] = 3] = "Collector";
10
+ UserCollectorType[UserCollectorType["Elite"] = 0] = "Elite";
11
11
  })(UserCollectorType || (exports.UserCollectorType = UserCollectorType = {}));
@@ -177,16 +177,15 @@ function submitEntry(g, account, raw) {
177
177
  new Date(g.startsAt) > now ||
178
178
  new Date(g.closesAt) <= now)
179
179
  throw new http_error_1.HttpError('This giveaway is not accepting entries', 409);
180
- const country = input.country || account.country;
180
+ const country = input.country;
181
181
  if (g.countries.length && (!country || !g.countries.includes(country)))
182
182
  throw new http_error_1.HttpError('This country is not eligible', 422);
183
183
  const at = now.toISOString();
184
184
  return {
185
185
  giveawayId: g._id,
186
186
  userId: account.userId,
187
- fullName: [account.firstName, account.lastName].filter(Boolean).join(' ').trim() || account.email,
187
+ name: [account.firstName?.trim(), account.lastName?.trim()].filter(Boolean).join(' '),
188
188
  email: account.email,
189
- username: account.username,
190
189
  country,
191
190
  _collectorType: account._collectorType,
192
191
  enteredAt: at,
@@ -53,12 +53,11 @@ export declare class GiveawayRepository {
53
53
  _id: string;
54
54
  email: string;
55
55
  _collectorType: UserCollectorType | null;
56
+ name: string;
56
57
  giveawayId: import("../types").GiveawayObjectId;
57
58
  enteredAt: string;
58
- username?: string | undefined;
59
59
  rulesSnapshot: string;
60
60
  userId: string;
61
- fullName: string;
62
61
  address?: import("../types").GiveawayDeliveryAddress | undefined;
63
62
  country?: string | undefined;
64
63
  rulesAcceptedAt: string;
@@ -22,6 +22,14 @@ function serialize(record) {
22
22
  return { ...record, _id: record._id.toHexString() };
23
23
  }
24
24
  const statuses = Object.values(giveaway_2.GiveawayStatus);
25
+ /** Normalize historical names and omit retired usernames without rewriting stored records. */
26
+ function normalizeEntry(record) {
27
+ const legacy = record;
28
+ const fields = { ...legacy };
29
+ delete fields.fullName;
30
+ delete fields.username;
31
+ return { ...fields, name: record.name ?? legacy.fullName ?? '' };
32
+ }
25
33
  function pagination(params) {
26
34
  const integer = (key, fallback, max) => {
27
35
  const value = Number(params.get(key));
@@ -411,9 +419,9 @@ class GiveawayRepository {
411
419
  const q = search(params);
412
420
  if (q)
413
421
  filter.$or = [
422
+ 'name',
414
423
  'fullName',
415
424
  '_id',
416
- 'username',
417
425
  'email',
418
426
  'userId',
419
427
  'address.line1',
@@ -470,7 +478,7 @@ class GiveawayRepository {
470
478
  .aggregate([...pipeline, { $facet: { data, total: [{ $count: 'count' }] } }])
471
479
  .next();
472
480
  return {
473
- data: result?.data || [],
481
+ data: (result?.data || []).map(normalizeEntry),
474
482
  total: result?.total[0]?.count || 0,
475
483
  page,
476
484
  limit
@@ -542,6 +550,7 @@ class GiveawayRepository {
542
550
  return {
543
551
  data: data.map(w => ({
544
552
  ...w,
553
+ entry: normalizeEntry(w.entry),
545
554
  giveaway: { ...w.giveaway, status: (0, domain_1.effectiveStatus)(w.giveaway) }
546
555
  })),
547
556
  total,
@@ -716,7 +725,7 @@ class GiveawayRepository {
716
725
  })
717
726
  .limit(1000)
718
727
  .toArray();
719
- const entries = rows;
728
+ const entries = rows.map(normalizeEntry);
720
729
  const existing = await this.winners.findOne({ giveawayId: id, replacedAt: null }, { projection: { _id: 1 } });
721
730
  (0, domain_1.confirmWinners)(g, entries, !!existing, 'preview', input);
722
731
  return { entries, giveaway: { ...g, status: (0, domain_1.effectiveStatus)(g) } };
@@ -851,7 +860,7 @@ class GiveawayRepository {
851
860
  const updated = { ...g, selection, revision: g.revision + 1 };
852
861
  await this.updateGiveaway(updated, g.revision, session);
853
862
  await this.audit(actor, 'Winner selected: ' + input.method, id, entry._id + (selection.reason ? ': ' + selection.reason : ''), session);
854
- return { giveaway: updated, entry };
863
+ return { giveaway: updated, entry: normalizeEntry(entry) };
855
864
  });
856
865
  }
857
866
  async resetSelection(actor, id, revision, reason) {
@@ -956,7 +965,6 @@ class GiveawayRepository {
956
965
  _id: entry._id,
957
966
  giveawayId: entry.giveawayId,
958
967
  enteredAt: entry.enteredAt,
959
- username: entry.username,
960
968
  tickets: 1,
961
969
  rulesSnapshot: entry.rulesSnapshot
962
970
  },
@@ -1250,7 +1258,7 @@ class GiveawayRepository {
1250
1258
  ...marketingLookup
1251
1259
  ];
1252
1260
  if (marketingOnly)
1253
- pipeline.push({ $match: { marketingAllowed: true } }, { $project: { fullName: 1, email: 1 } });
1261
+ pipeline.push({ $match: { marketingAllowed: true } }, { $project: { name: 1, fullName: 1, email: 1 } });
1254
1262
  const cursor = this.entries.aggregate(pipeline, {
1255
1263
  batchSize: 100
1256
1264
  });
@@ -1276,11 +1284,12 @@ class GiveawayRepository {
1276
1284
  'Rules accepted'
1277
1285
  ]
1278
1286
  ]);
1279
- for await (const e of cursor) {
1287
+ for await (const record of cursor) {
1288
+ const e = normalizeEntry(record);
1280
1289
  const row = marketingOnly
1281
- ? [e.fullName, e.email]
1290
+ ? [e.name, e.email]
1282
1291
  : [
1283
- e.fullName,
1292
+ e.name,
1284
1293
  e.email,
1285
1294
  e.address?.line1 || '',
1286
1295
  e.address?.line2 || '',
@@ -70,12 +70,11 @@ export type GiveawayEntry = {
70
70
  _id: GiveawayEntryId;
71
71
  giveawayId: GiveawayObjectId;
72
72
  userId: string;
73
- fullName: string;
73
+ name: string;
74
74
  email: string;
75
75
  /** Historical entry addresses are retained; new entries collect delivery only at claim. */
76
76
  address?: GiveawayDeliveryAddress;
77
77
  country?: string;
78
- username?: string;
79
78
  /** Null only for legacy entries whose exact collector tier was not recorded. */
80
79
  _collectorType: UserCollectorType | null;
81
80
  enteredAt: string;
@@ -182,8 +181,6 @@ export type GiveawayOverviewData = {
182
181
  };
183
182
  export type GiveawayUserProfile = Pick<FbUser, 'email' | 'firstName' | 'lastName' | '_collectorType'> & {
184
183
  userId: string;
185
- username?: string;
186
- country?: string;
187
184
  };
188
185
  export type GiveawayPhysicalClaim = {
189
186
  fullName: string;
@@ -191,7 +188,7 @@ export type GiveawayPhysicalClaim = {
191
188
  contactNumber: string;
192
189
  };
193
190
  export type GiveawayTicket = {
194
- entry: Pick<GiveawayEntry, '_id' | 'giveawayId' | 'enteredAt' | 'username' | 'rulesSnapshot'> & {
191
+ entry: Pick<GiveawayEntry, '_id' | 'giveawayId' | 'enteredAt' | 'rulesSnapshot'> & {
195
192
  tickets: 1;
196
193
  };
197
194
  giveaway: Pick<Giveaway, '_id' | 'title' | 'image' | 'creditAmount' | 'closesAt' | 'status' | 'category'>;
@@ -9,7 +9,7 @@ export type FbUser = {
9
9
  };
10
10
  email: string;
11
11
  fcmTokens: Record<string, boolean>;
12
- firstName: string;
12
+ firstName?: string;
13
13
  fundAmount: number;
14
14
  fundalert: number;
15
15
  id: string;
@@ -20,7 +20,7 @@ export type FbUser = {
20
20
  isFacebookUser: boolean;
21
21
  lastCardIndex: number;
22
22
  lastGradingTime: number;
23
- lastName: string;
23
+ lastName?: string;
24
24
  soldCards: {
25
25
  count: number;
26
26
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dgc-core",
3
- "version": "2.0.1",
3
+ "version": "2.0.4",
4
4
  "description": "Shared DGC contracts, business rules and server utilities",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",