Resolving place in edit form.
This commit is contained in:
@@ -5,9 +5,11 @@ import { MerkleJson } from 'merkle-json';
|
||||
import moment from 'moment';
|
||||
import omit from 'object.omit';
|
||||
import convert from 'convert';
|
||||
import unprint from 'unprint';
|
||||
|
||||
import initLogger from './logger.js';
|
||||
import { knexOwner as knex, knexManticore } from './knex.js';
|
||||
import redis from './redis.js';
|
||||
import { utilsApi } from './manticore.js';
|
||||
import { HttpError } from './errors.js';
|
||||
import { fetchCountriesByAlpha2 } from './countries.js';
|
||||
@@ -18,6 +20,7 @@ import escape from '../utils/escape-manticore.js';
|
||||
import slugify from '../utils/slugify.js';
|
||||
import { curateRevision } from './revisions.js';
|
||||
import { interpolateProfiles } from '../common/actors.mjs'; // eslint-disable-line import/namespace
|
||||
import { resolvePlace } from '../common/geo.mjs'; // eslint-disable-line import/namespace
|
||||
|
||||
const logger = initLogger();
|
||||
const mj = new MerkleJson();
|
||||
@@ -816,14 +819,48 @@ export async function createActorRevision(actorId, {
|
||||
return [key, values];
|
||||
}).filter(Boolean));
|
||||
|
||||
const deltas = Object.entries(edits).map(([key, value]) => {
|
||||
const deltas = await Promise.all(Object.entries(edits).map(async ([key, value]) => {
|
||||
if (baseActor[key] === value || typeof value === 'undefined') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (['originPlace', 'residencePlay'].includes(key)) {
|
||||
console.log(key, value);
|
||||
throw new Error('must be converted first!');
|
||||
if (['originPlace', 'residencePlace'].includes(key)) {
|
||||
if (!value) {
|
||||
return [
|
||||
// { key: key.includes('origin') ? 'originCountry' : 'residenceCountry', value: null },
|
||||
{ key: key.includes('origin') ? 'originState' : 'residenceState', value: null },
|
||||
{ key: key.includes('origin') ? 'originCity' : 'residenceCity', value: null },
|
||||
];
|
||||
}
|
||||
|
||||
const resolvedLocation = await resolvePlace(value, {
|
||||
knex,
|
||||
redis,
|
||||
logger,
|
||||
slugify,
|
||||
unprint,
|
||||
}, {
|
||||
userAgent: 'contact via https://traxxx.me/',
|
||||
});
|
||||
|
||||
if (!resolvedLocation) {
|
||||
throw new Error(`Failed to resolve ${key} ${value}`);
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
key: key.includes('origin') ? 'originCountry' : 'residenceCountry',
|
||||
value: resolvedLocation.country,
|
||||
},
|
||||
{
|
||||
key: key.includes('origin') ? 'originState' : 'residenceState',
|
||||
value: resolvedLocation.state,
|
||||
},
|
||||
{
|
||||
key: key.includes('origin') ? 'originCity' : 'residenceCity',
|
||||
value: resolvedLocation.city,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
if (['cup', 'bust', 'waist', 'hip'].includes(key)) {
|
||||
@@ -902,7 +939,7 @@ export async function createActorRevision(actorId, {
|
||||
}
|
||||
|
||||
return { key, value };
|
||||
}).filter(Boolean);
|
||||
})).then((rawDeltas) => rawDeltas.flat().filter(Boolean));
|
||||
|
||||
const deltaComments = deltas.map((delta) => delta.comment);
|
||||
const curatedComment = [comment, ...deltaComments].filter(Boolean).join(' | ');
|
||||
|
||||
Reference in New Issue
Block a user