talatroi
Senior Member
Hi ae, nhờ ae tí, project này mình Node + typescript nên hơi rắc rối tí, mình maintain lại nên ko biết gì, ae giúp nhé vấnđề duy nhất là Image Upload nha ae,đó giờ mình ko dùng kiểu này nên ko biết sai ở đâu~~
Code ở Controller.ts
Code ở model.ts // mình thử dùng
* Data in Model
mình nghĩ tất cả các phần khác ok hết, khi mình dùng postman
mình console body + file ra thì
mình ko thấy sai ở đâu cả, nhờ ae giúp với, chiều nộp rồi
Code ở Controller.ts
JavaScript:
export const CreateConsultingData = async (req: Request, res: Response) => {
const {
// parent_page_id
name,
place,
contents,
attachment,
} = req.body;
const parent_page_id = process.env.PRONG_PAGE;
const file_nm = req.file
? config.MULTER_TYPE === "local"
? req.file.filename
: req.file.key
: undefined;
const file_org_nm = req.file ? req.file.originalname : undefined;
const file_url = req.file
? config.MULTER_TYPE === "local"
? "/file/" + file_nm
: req.file.location
: undefined;
try {
if (!parent_page_id || parent_page_id.length !== 24) {
return res
.status(400)
.send(
new FailedMessage(
MessageCode.CMS_COMMON_00001.error_code,
"parent_page_id값이 유효하지 않습니다."
)
);
}
const isValidParam = CheckPageParam(req.body);
if (!isValidParam) {
return res
.status(400)
.send(
new FailedMessage(
MessageCode.CMS_COMMON_00001.error_code,
MessageCode.CMS_COMMON_00001.description
)
);
}
await TransactionWrap(async (session) => {
const response = await ProngDB.CreateConsultingData(
{
parent_page_id,
name,
place,
file_nm, file_org_nm, file_url,
contents,
attachment,
},
{ session }
);
if (response) {
return res.send(new SuccessMessage(response));
} else {
return res
.status(400)
.send(
new FailedMessage(
MessageCode.CMS_DATA_00001.error_code,
MessageCode.CMS_DATA_00001.description
)
);
}
});
} catch (e) {
console.log(e);
res.status(500).send(new InternalErrorMessage());
}
console.log(req.file);
console.log(req.body);
};
Code ở model.ts // mình thử dùng
JavaScript:
export interface ProngModel {
_id?: ObjectId;
// parent_page_id: ObjectId;
page?: {
// name of the project you want to create
name: string;
place: string;
attachment: File;
//slug
file_nm:string; file_org_nm:string; file_url:string;
//Time created
//start day
//place
contents: string;
//sumary about what going on
// small title
//number of page
//notice or desc of the action
};
delete_at: boolean;
regist_dt: Date;
update_dt?: Date;
delete_dt?: Date;
}
* Data in Model
JavaScript:
export const CreateConsultingData = async (
param: {
parent_page_id: string;
name: string;
file_nm:string; file_org_nm:string; file_url:string;
//slug
// slug: string;
place: string;
//Time created
// createdAt: string;
contents: string;
attachment: File;
//sumary about what going on
// title: string;
// small title
// descriptionSmallTitle: string;
//breadscrum defination
// breadScrum: string;
//number of page
// paginationPage: number;
//notice or desc of the action
// Notification: number;
},
options?: { session?: ClientSession }
) => {
const prongColl = await DataCommonDB.GetDataCollection(param.parent_page_id);
if (!prongColl) {
return null;
}
const {
name,
place,
file_nm, file_org_nm, file_url,
contents,
attachment,
} = param;
const notice: ProngModel = {
// parent_page_id: new ObjectId(parent_page_id),
page: {
name,
place,
file_nm, file_org_nm, file_url,
contents,
attachment,
},
delete_at: false,
regist_dt: new Date(),
update_dt: new Date(),
};
const response = await prongColl.insertOne(notice, { ...options });
if (response) {
return {
...notice,
_id: response.insertedId,
};
} else {
return null;
}
};
mình console body + file ra thì
mình ko thấy sai ở đâu cả, nhờ ae giúp với, chiều nộp rồi
Last edited: