1 import { join } from 'path'
2 import { AfterDestroy, AllowNull, Column, CreatedAt, Model, Table, UpdatedAt } from 'sequelize-typescript'
3 import { Avatar } from '../../../shared/models/avatars/avatar.model'
4 import { unlinkPromise } from '../../helpers/core-utils'
5 import { CONFIG, STATIC_PATHS } from '../../initializers'
10 export class AvatarModel extends Model<AvatarModel> {
23 static removeFilesAndSendDelete (instance: AvatarModel) {
24 return instance.removeAvatar()
27 toFormattedJSON (): Avatar {
29 path: this.getWebserverPath(),
30 createdAt: this.createdAt,
31 updatedAt: this.updatedAt
36 return join(STATIC_PATHS.AVATARS, this.filename)
40 const avatarPath = join(CONFIG.STORAGE.AVATARS_DIR, this.filename)
41 return unlinkPromise(avatarPath)