Fix error handle

fix pagination issue
change logic for change passsword and profile update
This commit is contained in:
2026-02-10 13:25:50 +07:00
parent 1d3e79c546
commit 5ffdd7454a
26 changed files with 339 additions and 213 deletions

View File

@@ -0,0 +1,29 @@
import { AppError } from '@/lib/errors';
import fs, { writeFile } from 'fs/promises';
import path from 'path';
const uploadDir = './data/avatar';
export async function saveFile(key: string, file: Buffer | File) {
if (!uploadDir) {
throw new Error('Upload directory not found');
}
const fileBuffer =
file instanceof File ? Buffer.from(await file.arrayBuffer()) : file;
const filePath = path.join(uploadDir, key);
try {
await fs.mkdir(uploadDir, { recursive: true });
await writeFile(filePath, fileBuffer);
return key;
} catch (error) {
console.error(`Error saving file: ${key}`, error);
throw new AppError(
'FILE_SAVE_ERROR',
`Failed to save file: ${error instanceof Error ? error.message : 'Unknown error'}`,
500,
);
}
}