root 3 years ago
commit 92169362da

@ -9,7 +9,7 @@ const libphonenumberjs = require("libphonenumber-js");
const boom = require("boom"); const boom = require("boom");
// Get Data Models // Get Data Models
const { User,Counter, generateBookingId,resetCounter,generateCustomerId } = require('../models/User') const { User,Counter, generateBookingId,resetCounter,generateCustomerId,ProfilePicture} = require('../models/User')
//const User = require("../models/User"); //const User = require("../models/User");
const customJwtAuth = require("../customAuthJwt"); const customJwtAuth = require("../customAuthJwt");
@ -335,3 +335,32 @@ exports.delPhoneUser = async (req, reply) => {
throw boom.boomify(err); throw boom.boomify(err);
} }
}; };
exports.uploadProfilePicture = async (req, reply) => {
try {
const customerId = req.params.customerId;
const picture = new Buffer.from(req.body.picture, 'base64');
let profilePicture = await ProfilePicture.findOne({ customerId });
if (!profilePicture) {
profilePicture = new ProfilePicture({
customerId,
picture,
});
} else {
profilePicture. picture = picture;
}
await profilePicture.save();
reply.send({ message: 'Profile picture uploaded successfully' });
} catch (error) {
reply.status(500).send({ error: error.message });
}
};

@ -110,6 +110,19 @@ const userSchema = new mongoose.Schema(
}, },
{ versionKey: false } { versionKey: false }
); );
const profilePictureSchema = new Schema({
customerId: {
type: String,unique: true,
required: true
},
picture: {
type: Buffer,
required: true
}
});
const ProfilePicture = mongoose.model('ProfilePicture', profilePictureSchema);
const Counter = mongoose.model('Counter', CounterSchema); const Counter = mongoose.model('Counter', CounterSchema);
const User = mongoose.model("User", userSchema); const User = mongoose.model("User", userSchema);
@ -120,4 +133,4 @@ const User = mongoose.model("User", userSchema);
//module.exports = mongoose.model("User", userSchema); //module.exports = mongoose.model("User", userSchema);
module.exports = { User,Counter, generateCustomerId,generateBookingId ,resetCounter}; module.exports = { User,Counter, generateCustomerId,generateBookingId ,resetCounter,ProfilePicture};

@ -14,7 +14,7 @@ const tanksSchema = new mongoose.Schema({
blockName: { type: String, default: null }, blockName: { type: String, default: null },
capacity: { type: String, default: null }, capacity: { type: String, default: null },
typeOfWater: { type: String, default: null }, typeOfWater: { type: String, default: null },
water_level: { type: String, default: null },
tankLocation: { type: String, default: null }, tankLocation: { type: String, default: null },
connections: { connections: {
source: { type: String}, source: { type: String},

@ -379,5 +379,43 @@ module.exports = function (fastify, opts, next) {
// Login for a user is in the main index.js file. // Login for a user is in the main index.js file.
// fastify-jwt used to create the token was throwing exceptions and requierd // fastify-jwt used to create the token was throwing exceptions and requierd
// it be called before the route is loaded. // it be called before the route is loaded.
fastify.route({
method: "POST",
url: "/api/users/profile-picture/:customerId",
schema: {
tags: ["User"],
description: "This is for uploading profile picture.",
summary: "This is for uploading profile picture.",
params: {
type: "object",
properties: {
customerId: {
type: "string",
description: "customerId",
},
},
},
body: {
type: "object",
required: ["picture"],
properties: {
picture: {
type: 'string'
}
},
},
security: [
{
basicAuth: [],
},
],
},
handler: userController.uploadProfilePicture,
});
next(); next();
}; };

Loading…
Cancel
Save