Separated some actor edit types into dedicated components.

This commit is contained in:
2024-11-03 06:30:09 +01:00
parent 94ebc92789
commit 89c55cea93
19 changed files with 1096 additions and 737 deletions

View File

@@ -114,6 +114,10 @@ export function curateActor(actor, context = {}) {
},
agency: actor.agency,
avatar: curateMedia(actor.avatar),
socials: context.socials?.map((social) => ({
url: social.url,
platform: social.platform,
})),
profiles: context.profiles?.map((profile) => ({
id: profile.id,
description: profile.description,
@@ -165,7 +169,7 @@ export function sortActorsByGender(actors, context = {}) {
}
export async function fetchActorsById(actorIds, options = {}, reqUser) {
const [actors, profiles, photos, stashes] = await Promise.all([
const [actors, profiles, photos, socials, stashes] = await Promise.all([
knex('actors')
.select(
'actors.*',
@@ -212,6 +216,8 @@ export async function fetchActorsById(actorIds, options = {}, reqUser) {
.leftJoin('media', 'media.id', 'actors_avatars.media_id')
.groupBy('media.id', 'actors_avatars.actor_id')
.orderBy(knex.raw('max(actors_avatars.created_at)'), 'desc'),
knex('actors_social')
.whereIn('actor_id', actorIds),
reqUser
? knex('stashes_actors')
.leftJoin('stashes', 'stashes.id', 'stashes_actors.stash_id')
@@ -239,6 +245,7 @@ export async function fetchActorsById(actorIds, options = {}, reqUser) {
stashes: stashes.filter((stash) => stash.actor_id === actor.id),
profiles: profiles.filter((profile) => profile.actor_id === actor.id),
photos: photos.filter((photo) => photo.actor_id === actor.id),
socials: socials.filter((social) => social.actor_id === actor.id),
append: options.append,
});
}).filter(Boolean);
@@ -829,12 +836,17 @@ export async function createActorRevision(actorId, {
return null;
}
if (key === 'residenceCountry' && edits.residenceCountry) {
if (key === 'residenceCountry' && edits.residencePlace) {
// place overrides country
return null;
}
if (['originPlace', 'residencePlace'].includes(key)) {
if (!value && !baseActor[key]) {
// don't pollute deltas if value is already unset
return null;
}
if (!value) {
return [
// { key: key.includes('origin') ? 'originCountry' : 'residenceCountry', value: null },