Added actor creation page.

This commit is contained in:
2026-05-20 05:27:37 +02:00
parent 35ffc2b0f7
commit dc80e1e199
6 changed files with 220 additions and 64 deletions

View File

@@ -3,6 +3,7 @@ import { differenceInYears } from 'date-fns';
import { unit } from 'mathjs';
import { MerkleJson } from 'merkle-json';
import moment from 'moment';
import { nanoid } from 'nanoid';
import omit from 'object.omit';
import convert from 'convert';
import unprint from 'unprint';
@@ -521,6 +522,27 @@ export async function fetchActors(filters, rawOptions, reqUser) {
};
}
function curateActorEntry(actor, context) {
return {
name: actor.name,
slug: slugify(actor.name),
entry_id: nanoid(), // allows for manual creation of multiple actors with the same name
gender: actor.gender,
comment: context?.comment,
};
}
export async function createActor(newActor, context, reqUser) {
if (!reqUser || reqUser.role === 'user') {
throw new HttpError('You are not permitted to create actors', 403);
}
const curatedActorEntry = curateActorEntry(newActor, context);
const [actorEntry] = await knex('actors').insert(curatedActorEntry).returning('*');
return curateActor(actorEntry);
}
export async function fetchActorRevisions(revisionId, filters = {}, reqUser) {
const limit = filters.limit || 50;
const page = filters.page || 1;