Fix: Db Profile
Deskripsi: - Menghapus field imagesId dan imagesBackgroundId - Menhapus table backgroundImage - Menghapus component avatar dan header card yang lama ## No Issue
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import fs from "fs";
|
||||
import _ from "lodash";
|
||||
import { v4 } from "uuid";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param formData
|
||||
* @returns upload gambar ke /public/img
|
||||
*/
|
||||
export async function funUploadFoto(formData: FormData, id: string) {
|
||||
const file: any = formData.get("file");
|
||||
const fName = file.name;
|
||||
const fExt = _.lowerCase(file.name.split(".").pop());
|
||||
const fRandomName = v4(fName) + "." + fExt;
|
||||
|
||||
const upload = await prisma.images.create({
|
||||
data: {
|
||||
url: fRandomName,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
url: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (upload) {
|
||||
await prisma.profile.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data: {
|
||||
imagesId: upload.id,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const upFolder = Buffer.from(await file.arrayBuffer());
|
||||
fs.writeFileSync(`./public/img/${upload.url}`, upFolder);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: upload,
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import { MODEL_USER } from "@/app_modules/home/model/interface";
|
||||
import { MODEL_IMAGES } from "@/app_modules/model_global/interface";
|
||||
|
||||
export interface MODEL_PROFILE {
|
||||
userId: string;
|
||||
@@ -12,10 +11,6 @@ export interface MODEL_PROFILE {
|
||||
active: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
ImageProfile: MODEL_IMAGES;
|
||||
imagesId: string;
|
||||
ImagesBackground: MODEL_IMAGES;
|
||||
imagesBackgroundId: string;
|
||||
imageId?: string;
|
||||
imageBackgroundId?: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user