From 91d1214a7b7b15694df7b9ac1ce2ae817318b641 Mon Sep 17 00:00:00 2001 From: Z8MB1E Date: Fri, 21 Aug 2026 15:39:36 -0400 Subject: [PATCH] feat(profiles): add award metadata --- src/collections/users/Profiles.ts | 59 ++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 9 deletions(-) diff --git a/src/collections/users/Profiles.ts b/src/collections/users/Profiles.ts index cbe9975..c151a31 100644 --- a/src/collections/users/Profiles.ts +++ b/src/collections/users/Profiles.ts @@ -107,21 +107,29 @@ export const Profiles: CollectionConfig = { let xpAcc = 0; const progressionData = siblingData as { - awards?: number[]; + awards?: Array<{ + award?: number | Award; + } | number>; scoreboard?: Record; minigames?: { flappyBird?: { xpEarned?: number | null } }; }; const awardsList = progressionData?.awards || []; + const awardIds = awardsList.flatMap((entry) => { + const award = typeof entry === "object" ? entry.award : entry; + if (typeof award === "number") return [award]; + if (award && typeof award.id === "number") return [award.id]; + return []; + }); const scoreboard = progressionData?.scoreboard || {}; const flappyXp = progressionData?.minigames?.flappyBird?.xpEarned ?? 0; - if (awardsList.length > 0) { + if (awardIds.length > 0) { await req.payload .find({ collection: "awards", where: { id: { - in: awardsList, + in: awardIds, }, }, }) @@ -159,12 +167,45 @@ export const Profiles: CollectionConfig = { }, { name: "awards", - type: "relationship", - relationTo: "awards", - hasMany: true, - admin: { - appearance: "drawer", - }, + type: "array", + fields: [ + { + name: "award", + type: "relationship", + relationTo: "awards", + required: true, + admin: { + appearance: "drawer" + }, + }, + { + name: "awardedBy", + type: "relationship", + relationTo: "profiles", + // This is a self-relation. Do not recursively populate the + // issuer's progression/awards when a profile is read. + maxDepth: 0, + admin: { + description: 'Who issued the award. If no one, the award will be attributed as "on behalf of the unit."', + }, + }, + { + name: "awardedAt", + type: "date", + required: true, + defaultValue: () => new Date().toISOString(), + admin: { + description: "The issuing date of the award.", + }, + }, + { + name: "awardReason", + type: "textarea", + admin: { + description: "An optional reason for the award.", + }, + }, + ], }, { name: "qualifications",