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;
const progressionData = siblingData as {
awards?: number[];
awards?: Array<{
award?: number | Award;
} | number>;
scoreboard?: Record<string, number | null>;
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",