Fix issue #72: Link actor with a discord user
All checks were successful
Test / test (push) Successful in 2s

This commit is contained in:
Gitea OpenCode Agent
2026-10-15 17:06:25 +00:00
parent b0cc98a452
commit 299380d143
8 changed files with 570 additions and 9 deletions

View File

@@ -54,6 +54,10 @@ const ActorSchema = new Schema({
default: null
},
foundryActorId: { type: String },
// The Discord player this character belongs to (Syndria98/dragonroll#72): each player
// of the server a campaign is linked to holds one character of it. Only
// routes/discord.js writes it, so the campaign keeps owning it whichever guild claimed it.
discordUserId: { type: String, default: null },
date: { type: Date, default: Date.now }
});
@@ -62,4 +66,10 @@ ActorSchema.index(
{ unique: true, partialFilterExpression: { foundryActorId: { $type: 'string' } } }
);
// A player holds at most one character of a campaign: the id is unique within it.
ActorSchema.index(
{ campaign: 1, discordUserId: 1 },
{ unique: true, partialFilterExpression: { discordUserId: { $type: 'string' } } }
);
module.exports = mongoose.model('Actor', ActorSchema);