2020-02-19 15:39:35 +01:00
|
|
|
import { Avatar } from '@shared/models'
|
2020-05-29 16:16:55 +02:00
|
|
|
import { buildUrl } from '../helpers/utils'
|
2020-02-19 15:39:35 +01:00
|
|
|
|
|
|
|
function formatAvatarForAPI (obj: { avatar?: Avatar }) {
|
|
|
|
if (!obj.avatar) return null
|
|
|
|
|
|
|
|
return {
|
|
|
|
path: obj.avatar.path,
|
|
|
|
createdAt: obj.avatar.createdAt,
|
|
|
|
updatedAt: obj.avatar.updatedAt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-29 16:16:55 +02:00
|
|
|
function formatAvatarForDB (obj: { avatar?: Avatar, 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
|
|
|
|
}
|