2020-06-09 14:29:20 +02:00
|
|
|
|
2021-05-03 16:52:54 +02:00
|
|
|
import { ActorImage } from '@shared/models'
|
2020-05-29 16:16:55 +02:00
|
|
|
import { buildUrl } from '../helpers/utils'
|
2020-02-19 15:39:35 +01:00
|
|
|
|
2021-05-03 16:52:54 +02:00
|
|
|
function formatAvatarForAPI (obj: { avatar?: ActorImage & { url: string } }) {
|
2020-02-19 15:39:35 +01:00
|
|
|
if (!obj.avatar) return null
|
|
|
|
|
|
|
|
return {
|
2020-06-09 14:29:20 +02:00
|
|
|
url: obj.avatar.url,
|
2020-02-19 15:39:35 +01:00
|
|
|
path: obj.avatar.path,
|
|
|
|
createdAt: obj.avatar.createdAt,
|
|
|
|
updatedAt: obj.avatar.updatedAt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-03 16:52:54 +02:00
|
|
|
function formatAvatarForDB (obj: { avatar?: ActorImage, host: string }) {
|
2020-02-19 15:39:35 +01:00
|
|
|
if (!obj.avatar) return null
|
|
|
|
|
|
|
|
return {
|
2020-05-29 16:16:55 +02:00
|
|
|
url: buildUrl(obj.host, obj.avatar.path),
|
2020-02-19 15:39:35 +01:00
|
|
|
path: obj.avatar.path,
|
|
|
|
createdAt: obj.avatar.createdAt,
|
|
|
|
updatedAt: obj.avatar.updatedAt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildAvatarMapping () {
|
|
|
|
return {
|
|
|
|
path: {
|
|
|
|
type: 'keyword'
|
|
|
|
},
|
|
|
|
createdAt: {
|
|
|
|
type: 'date',
|
|
|
|
format: 'date_optional_time'
|
|
|
|
},
|
|
|
|
updatedAt: {
|
|
|
|
type: 'date',
|
|
|
|
format: 'date_optional_time'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
formatAvatarForAPI,
|
|
|
|
formatAvatarForDB,
|
|
|
|
buildAvatarMapping
|
|
|
|
}
|