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;
|
||||
|
||||
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",
|
||||
|
|
|
|||
Loading…
Reference in a new issue