This commit is contained in:
David Arranz 2024-09-23 18:47:24 +02:00
parent 133bcec868
commit ef3a9c3576
2 changed files with 6 additions and 11 deletions

View File

@ -63,8 +63,8 @@ export class UploadProfileLogoUseCase
return this._saveProfile(profile);
}
private async _deleteOldLogo(filename) {
const logo_path = `${this._defaults.dealer_logos_upload_path}/${filename}`;
private async _deleteOldLogo(logo: ProfileLogotype) {
const logo_path = logo.relativePath();
await fs.rm(logo_path);
}
@ -88,14 +88,14 @@ export class UploadProfileLogoUseCase
private async _getProfileDealer(userId: UniqueID) {
const transaction = this._adapter.startTransaction();
const dealerRepoBuilder = this._getProfileRepository();
const profileRepoBuilder = this._getProfileRepository();
let profile: Profile | null = null;
try {
await transaction.complete(async (t) => {
const dealerRepo = dealerRepoBuilder({ transaction: t });
profile = await dealerRepo.getByUserId(userId);
const profileRepo = profileRepoBuilder({ transaction: t });
profile = await profileRepo.getByUserId(userId);
});
if (!profile) {

View File

@ -2,7 +2,6 @@ import { config } from "@/config";
import { IValueObjectOptions, Result, ValueObject } from "@shared/contexts";
import fs from "fs/promises";
import mime from "mime-types";
import path from "path";
export interface IProfileLogotypeOptions extends IValueObjectOptions {}
@ -38,12 +37,8 @@ export class ProfileLogotype extends ValueObject<string> {
}
public relativePath() {
// `${context.defaults.dealer_logos_upload_path}/${profile.logo}`
return this.filename
? path.format({
base: config.defaults.dealer_logos_upload_path,
name: this.filename,
})
? `${config.defaults.dealer_logos_upload_path}/${this.filename}`
: config.defaults.dealer_logo_placeholder;
}