sepia-search-motore-di-rice.../server/lib/elastic-search-avatar.ts

48 lines
926 B
TypeScript
Raw Normal View History

2020-06-09 14:29:20 +02:00
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
2020-06-09 14:29:20 +02:00
function formatAvatarForAPI (obj: { avatar?: Avatar & { 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
}
}
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
}