profile picture

master
bhaskar 2 years ago
parent 4420562f10
commit 5c1fe0fe86

2
node_modules/.package-lock.json generated vendored

@ -1,7 +1,7 @@
{
"name": "armintatankapi",
"version": "1.0.0",
"lockfileVersion": 3,
"lockfileVersion": 2,
"requires": true,
"packages": {
"node_modules/@adminjs/design-system": {

@ -1257,7 +1257,7 @@ exports.uploadProfilePicture = async (req, res) => {
}
const supplierId = req.params.supplierId;
const picture = req.file.filename; // Assuming the file field in the request is named 'picture'
const picture = req.file.filename;
let profilePicture = await ProfilePictureSupplier.findOne({ supplierId });

@ -325,7 +325,9 @@ fastify.get('/testtemp', (req, reply) => {
reply.view('layouts/main', {});
});
const multipart = require('fastify-multipart');
fastify.register(multipart);
//fastify-auth plugin is required so we can define routes in seperate files and verify jwt supplied in preHandlers for each request.
//const multer = require("fastify-multer");
fastify.register(require("fastify-auth"));

@ -132,17 +132,34 @@ const supplierSchema = new mongoose.Schema(
fcmId: { type: String, default: null },
});
const profilePictureSupplierSchema = new Schema({
// supplierId: {
// type: String,unique: true,
// required: true
// },
// const profilePictureSupplierSchema = new Schema({
// // supplierId: {
// // type: String,unique: true,
// // required: true
// // },
// // // picture: {
// // // type: String,
// // // required: true
// // // }
// // picture: {
// // type: String,
// // required: true
// // required: true,
// // validate: {
// // validator: function (value) {
// // const supportedFormats = ['jpg', 'jpeg', 'png'];
// // const fileExtension = value.split('.').pop().toLowerCase();
// // return supportedFormats.includes(fileExtension);
// // },
// // message: 'Picture must be a JPEG, PNG or JPG image'
// // }
// picture: {
// // }
// supplierId: {
// type: String,
// unique: true,
// required: true
// },
// picture: {
// type: Buffer,
// required: true,
// validate: {
// validator: function (value) {
@ -150,16 +167,19 @@ const supplierSchema = new mongoose.Schema(
// const fileExtension = value.split('.').pop().toLowerCase();
// return supportedFormats.includes(fileExtension);
// },
// message: 'Picture must be a JPEG, PNG or JPG image'
// message: 'Picture must be a JPEG, PNG, or JPG image'
// }
// }
// });
const profilePictureSupplierSchema = new Schema({
supplierId: {
type: String,
unique: true,
required: true
},
picture: {
type: Buffer, // Store the file as binary data
type: String, // Change the type to String
required: true,
validate: {
validator: function (value) {

@ -577,6 +577,59 @@ module.exports = function (fastify, opts, next) {
// });
// fastify.route({
// method: 'POST',
// url: '/api/users/profile-picture-supplier',
// schema: {
// tags: ['Supplier'],
// description: 'Upload a profile picture for a supplier',
// summary: 'Upload a profile picture for a supplier',
// params: {
// type: 'object',
// properties: {
// supplierId: {
// type: 'string',
// description: 'Supplier ID',
// },
// },
// },
// consumes: ['multipart/form-data'],
// body: {
// type: 'object',
// properties: {
// picture: {
// type: 'string',
// description: 'Profile picture file',
// },
// },
// required: ['picture'],
// },
// response: {
// 200: {
// description: 'Profile picture uploaded successfully',
// type: 'object',
// properties: {
// message: { type: 'string' },
// },
// },
// 400: {
// description: 'Failed to upload profile picture',
// type: 'object',
// properties: {
// error: { type: 'string' },
// },
// },
// 500: {
// description: 'Internal server error',
// type: 'object',
// properties: {
// error: { type: 'string' },
// },
// },
// },
// },
// handler: validationHandler.uploadProfilePicture,
// });
fastify.route({
method: 'POST',
url: '/api/users/profile-picture-supplier/:supplierId',
@ -598,8 +651,13 @@ module.exports = function (fastify, opts, next) {
type: 'object',
properties: {
picture: {
type: 'string',
description: 'Profile picture file',
type: 'object',
properties: {
data: { type: 'string' }, // Remove the "format" property
encoding: { type: 'string' },
filename: { type: 'string' },
},
required: ['data', 'encoding', 'filename'], // Add required properties
},
},
required: ['picture'],
@ -632,7 +690,6 @@ module.exports = function (fastify, opts, next) {
});
const multer = require('multer');
const fs = require('fs');

Loading…
Cancel
Save