feat(profiles): add award metadata
This commit is contained in:
parent
1dfbb58dae
commit
91d1214a7b
1 changed files with 50 additions and 9 deletions
|
|
@ -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,13 +167,46 @@ export const Profiles: CollectionConfig = {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "awards",
|
name: "awards",
|
||||||
|
type: "array",
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: "award",
|
||||||
type: "relationship",
|
type: "relationship",
|
||||||
relationTo: "awards",
|
relationTo: "awards",
|
||||||
hasMany: true,
|
required: true,
|
||||||
admin: {
|
admin: {
|
||||||
appearance: "drawer",
|
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",
|
||||||
type: "relationship",
|
type: "relationship",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue