1
0
Fork 0

feat(profiles): add award metadata

This commit is contained in:
Jason Fraley 2026-08-21 15:39:36 -04:00
parent 1dfbb58dae
commit 91d1214a7b

View file

@ -107,21 +107,29 @@ export const Profiles: CollectionConfig = {
let xpAcc = 0; let xpAcc = 0;
const progressionData = siblingData as { const progressionData = siblingData as {
awards?: number[]; awards?: Array<{
award?: number | Award;
} | number>;
scoreboard?: Record<string, number | null>; scoreboard?: Record<string, number | null>;
minigames?: { flappyBird?: { xpEarned?: number | null } }; minigames?: { flappyBird?: { xpEarned?: number | null } };
}; };
const awardsList = progressionData?.awards || []; 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 scoreboard = progressionData?.scoreboard || {};
const flappyXp = progressionData?.minigames?.flappyBird?.xpEarned ?? 0; const flappyXp = progressionData?.minigames?.flappyBird?.xpEarned ?? 0;
if (awardsList.length > 0) { if (awardIds.length > 0) {
await req.payload await req.payload
.find({ .find({
collection: "awards", collection: "awards",
where: { where: {
id: { id: {
in: awardsList, in: awardIds,
}, },
}, },
}) })
@ -159,12 +167,45 @@ export const Profiles: CollectionConfig = {
}, },
{ {
name: "awards", name: "awards",
type: "relationship", type: "array",
relationTo: "awards", fields: [
hasMany: true, {
admin: { name: "award",
appearance: "drawer", 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", name: "qualifications",