This commit is contained in:
parent
2bc5041f08
commit
c6b13812fe
|
@ -12,31 +12,33 @@ const parser = new DatauriParser();
|
|||
export const register = async (req, res) => {
|
||||
try {
|
||||
const {
|
||||
fName,
|
||||
lName,
|
||||
// fName,
|
||||
// lName,
|
||||
email,
|
||||
password,
|
||||
phone,
|
||||
address1,
|
||||
address2,
|
||||
city,
|
||||
province,
|
||||
country,
|
||||
zip,
|
||||
username,
|
||||
type,
|
||||
status,
|
||||
transactions,
|
||||
// phone,
|
||||
// address1,
|
||||
// address2,
|
||||
// city,
|
||||
// province,
|
||||
// country,
|
||||
// zip,
|
||||
// username,
|
||||
// type,
|
||||
// status,
|
||||
// transactions,
|
||||
} = req.body;
|
||||
cloudinary.config({
|
||||
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
|
||||
api_key: process.env.CLOUDINARY_API_KEY,
|
||||
api_secret: process.env.CLOUDINARY_API_SECRET,
|
||||
});
|
||||
// const result = await User.dropIndex('username_1');
|
||||
// const result = await User.collection.dropIndex('username_1');
|
||||
const salt = await bcrypt.genSalt();
|
||||
const passwordHash = await bcrypt.hash(password, salt);
|
||||
const emailTaken = await User.findOne({ email: email });
|
||||
const usernameTaken = await User.findOne({ username: username });
|
||||
// const usernameTaken = await User.findOne({ username: username });
|
||||
|
||||
// const phoneTaken = await User.findOne({ phone: phone });
|
||||
const pic = null;
|
||||
|
@ -49,24 +51,24 @@ export const register = async (req, res) => {
|
|||
});
|
||||
}
|
||||
|
||||
if (!emailTaken && !usernameTaken) {
|
||||
if (!emailTaken) {
|
||||
const newUser = new User({
|
||||
fName,
|
||||
lName,
|
||||
// fName,
|
||||
// lName,
|
||||
email,
|
||||
password: passwordHash,
|
||||
phone,
|
||||
address1,
|
||||
address2,
|
||||
city,
|
||||
province,
|
||||
country,
|
||||
zip,
|
||||
username,
|
||||
type,
|
||||
status,
|
||||
transactions,
|
||||
photo: pic ? pic : "",
|
||||
// phone,
|
||||
// address1,
|
||||
// address2,
|
||||
// city,
|
||||
// province,
|
||||
// country,
|
||||
// zip,
|
||||
// username,
|
||||
// type,
|
||||
// status,
|
||||
// transactions,
|
||||
// photo: pic ? pic : "",
|
||||
});
|
||||
const usersaved = await newUser.save();
|
||||
const user = await User.findOne({ email: email });
|
||||
|
@ -113,7 +115,7 @@ export const login = async (req, res) => {
|
|||
const user = await User.findOne().or([
|
||||
{ email: users },
|
||||
{ phone: users },
|
||||
{ username: users },
|
||||
// { username: users },
|
||||
]);
|
||||
if (!user) {
|
||||
console.log("does not exist");
|
||||
|
|
|
@ -38,6 +38,27 @@ export const updateCollection = async (req, res, next) => {
|
|||
}
|
||||
};
|
||||
|
||||
export const updateCollectionByEndpoint = async (req, res, next) => {
|
||||
try {
|
||||
const { id, endpoint_id } = req.params;
|
||||
|
||||
const updatedCollection = await Collection.findByIdAndUpdate(
|
||||
req.params.id,
|
||||
{ $push: { endpoints: req.body.endpoint_id } },
|
||||
{ new: true }
|
||||
);
|
||||
|
||||
if (updatedCollection) {
|
||||
console.log("Updated Collection:", endpoint_id);
|
||||
res.status(200).json(updatedCollection);
|
||||
} else {
|
||||
res.status(404).json({ endpoint: "Collection or endpoint not found." });
|
||||
}
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteCollection = async (req, res, next) => {
|
||||
try {
|
||||
const getCollection = await Collection.findByIdAndDelete(req.params.id);
|
||||
|
@ -54,7 +75,12 @@ export const deleteCollection = async (req, res, next) => {
|
|||
};
|
||||
export const getCollections = async (req, res, next) => {
|
||||
try {
|
||||
const getCollection = await Collection.find();
|
||||
const getCollection = await Collection.find()
|
||||
.populate({
|
||||
path: "endpoints",
|
||||
model: "Endpoint",
|
||||
})
|
||||
.exec();
|
||||
// const Collection = getCollection.reverse();
|
||||
if (getCollection) {
|
||||
res.status(200).json(getCollection);
|
||||
|
@ -71,11 +97,9 @@ export const getCollection = async (req, res, next) => {
|
|||
try {
|
||||
const foundCollection = await Collection.findById(req.params.id)
|
||||
.populate({
|
||||
path: "userRef",
|
||||
model: "User",
|
||||
// select: "fName lName username photo",
|
||||
path: "endpoints",
|
||||
model: "Endpoint",
|
||||
})
|
||||
|
||||
.exec();
|
||||
|
||||
if (foundCollection) {
|
||||
|
|
|
@ -66,19 +66,19 @@ export const getUserId = async (req, res) => {
|
|||
export const updateUser = async (req, res, next) => {
|
||||
try {
|
||||
const {
|
||||
fName,
|
||||
lName,
|
||||
// fName,
|
||||
// lName,
|
||||
email,
|
||||
phone,
|
||||
address1,
|
||||
address2,
|
||||
city,
|
||||
province,
|
||||
country,
|
||||
zip,
|
||||
type,
|
||||
status,
|
||||
transactions,
|
||||
// phone,
|
||||
// address1,
|
||||
// address2,
|
||||
// city,
|
||||
// province,
|
||||
// country,
|
||||
// zip,
|
||||
// type,
|
||||
// status,
|
||||
// transactions,
|
||||
} = req.body;
|
||||
|
||||
const emailTaken = await User.findOne({ email: email });
|
||||
|
@ -101,20 +101,20 @@ export const updateUser = async (req, res, next) => {
|
|||
});
|
||||
if (!emailTaken && !taken) {
|
||||
const newUser = {
|
||||
fName,
|
||||
lName,
|
||||
// fName,
|
||||
// lName,
|
||||
email,
|
||||
phone,
|
||||
address1,
|
||||
address2,
|
||||
city,
|
||||
province,
|
||||
country,
|
||||
zip,
|
||||
type,
|
||||
status,
|
||||
transactions,
|
||||
photo: result.secure_url,
|
||||
// phone,
|
||||
// address1,
|
||||
// address2,
|
||||
// city,
|
||||
// province,
|
||||
// country,
|
||||
// zip,
|
||||
// type,
|
||||
// status,
|
||||
// transactions,
|
||||
// photo: result.secure_url,
|
||||
};
|
||||
const updatedUser = await User.findByIdAndUpdate(
|
||||
req.params.id,
|
||||
|
@ -130,18 +130,18 @@ export const updateUser = async (req, res, next) => {
|
|||
} else if (!req.file) {
|
||||
if (!emailTaken && !taken) {
|
||||
const newUser = {
|
||||
fName,
|
||||
lName,
|
||||
// fName,
|
||||
// lName,
|
||||
email,
|
||||
phone,
|
||||
address1,
|
||||
address2,
|
||||
city,
|
||||
province,
|
||||
country,
|
||||
zip,
|
||||
transactions,
|
||||
status,
|
||||
// phone,
|
||||
// address1,
|
||||
// address2,
|
||||
// city,
|
||||
// province,
|
||||
// country,
|
||||
// zip,
|
||||
// transactions,
|
||||
// status,
|
||||
};
|
||||
const updatedUser = await User.findByIdAndUpdate(
|
||||
req.params.id,
|
||||
|
@ -153,18 +153,18 @@ export const updateUser = async (req, res, next) => {
|
|||
res.status(500).json({ error: "email taken" });
|
||||
} else if (taken) {
|
||||
const newUser = {
|
||||
fName,
|
||||
lName,
|
||||
// fName,
|
||||
// lName,
|
||||
email,
|
||||
phone,
|
||||
address1,
|
||||
address2,
|
||||
city,
|
||||
province,
|
||||
country,
|
||||
zip,
|
||||
transactions,
|
||||
status,
|
||||
// phone,
|
||||
// address1,
|
||||
// address2,
|
||||
// city,
|
||||
// province,
|
||||
// country,
|
||||
// zip,
|
||||
// transactions,
|
||||
// status,
|
||||
};
|
||||
const updatedUser = await User.findByIdAndUpdate(
|
||||
req.params.id,
|
||||
|
|
|
@ -21,6 +21,12 @@ const CollectionSchema = mongoose.Schema(
|
|||
//required: true,
|
||||
},
|
||||
],
|
||||
endpoints: [
|
||||
{
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: "Endpoint",
|
||||
},
|
||||
],
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
|
|
@ -18,12 +18,12 @@ const EndpointSchema = mongoose.Schema(
|
|||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: "Collection",
|
||||
},
|
||||
created_by: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: "User",
|
||||
},
|
||||
// created_by: {
|
||||
// type: mongoose.Schema.Types.ObjectId,
|
||||
// ref: "User",
|
||||
// },
|
||||
body_json: {
|
||||
type: String,
|
||||
type: Array,
|
||||
},
|
||||
form_data: [
|
||||
{
|
||||
|
|
184
models/User.js
184
models/User.js
|
@ -2,18 +2,18 @@ import mongoose from "mongoose";
|
|||
|
||||
const UserSchema = new mongoose.Schema(
|
||||
{
|
||||
fName: {
|
||||
type: String,
|
||||
// required: true,
|
||||
min: 2,
|
||||
max: 50,
|
||||
},
|
||||
lName: {
|
||||
type: String,
|
||||
// required: true,
|
||||
min: 2,
|
||||
max: 50,
|
||||
},
|
||||
// fName: {
|
||||
// type: String,
|
||||
// // required: true,
|
||||
// min: 2,
|
||||
// max: 50,
|
||||
// },
|
||||
// lName: {
|
||||
// type: String,
|
||||
// // required: true,
|
||||
// min: 2,
|
||||
// max: 50,
|
||||
// },
|
||||
email: {
|
||||
type: String,
|
||||
required: true,
|
||||
|
@ -24,93 +24,93 @@ const UserSchema = new mongoose.Schema(
|
|||
type: String,
|
||||
// required: true,
|
||||
max: 30,
|
||||
unique: true,
|
||||
unique: false,
|
||||
},
|
||||
password: {
|
||||
type: String,
|
||||
required: true,
|
||||
min: 5,
|
||||
},
|
||||
phone: {
|
||||
type: String,
|
||||
// phone: {
|
||||
// type: String,
|
||||
// // required: true,
|
||||
// default: "",
|
||||
// },
|
||||
// photo: {
|
||||
// type: String,
|
||||
// },
|
||||
// address1: {
|
||||
// type: String,
|
||||
// default: "",
|
||||
// },
|
||||
// address2: {
|
||||
// type: String,
|
||||
// default: "",
|
||||
// },
|
||||
// city: {
|
||||
// type: String,
|
||||
// default: "",
|
||||
// },
|
||||
// province: {
|
||||
// type: String,
|
||||
// default: "",
|
||||
// },
|
||||
// country: {
|
||||
// type: String,
|
||||
// default: "",
|
||||
// },
|
||||
// zip: {
|
||||
// type: String,
|
||||
// default: "",
|
||||
// },
|
||||
// type: {
|
||||
// type: String,
|
||||
// default: "client",
|
||||
// },
|
||||
// status: {
|
||||
// type: String,
|
||||
// default: "new",
|
||||
// required: true,
|
||||
default: "",
|
||||
},
|
||||
photo: {
|
||||
type: String,
|
||||
},
|
||||
address1: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
address2: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
city: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
province: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
country: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
zip: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
default: "client",
|
||||
},
|
||||
status: {
|
||||
type: String,
|
||||
default: "new",
|
||||
required: true,
|
||||
},
|
||||
phoneStatus: {
|
||||
type: String,
|
||||
default: "new",
|
||||
// required: true,
|
||||
},
|
||||
kycStatus: {
|
||||
type: String,
|
||||
default: "new",
|
||||
// required: true,
|
||||
},
|
||||
kycRef: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: "Kyc",
|
||||
},
|
||||
friends: [
|
||||
{
|
||||
number: {
|
||||
type: String,
|
||||
required: false,
|
||||
},
|
||||
favorite: {
|
||||
type: Boolean,
|
||||
required: false,
|
||||
default: false,
|
||||
},
|
||||
nickname: {
|
||||
type: String,
|
||||
required: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
otp: {
|
||||
type: String,
|
||||
default: null,
|
||||
},
|
||||
otpExpiration: {
|
||||
type: Date,
|
||||
default: null,
|
||||
},
|
||||
// },
|
||||
// phoneStatus: {
|
||||
// type: String,
|
||||
// default: "new",
|
||||
// // required: true,
|
||||
// },
|
||||
// kycStatus: {
|
||||
// type: String,
|
||||
// default: "new",
|
||||
// // required: true,
|
||||
// },
|
||||
// kycRef: {
|
||||
// type: mongoose.Schema.Types.ObjectId,
|
||||
// ref: "Kyc",
|
||||
// },
|
||||
// friends: [
|
||||
// {
|
||||
// number: {
|
||||
// type: String,
|
||||
// required: false,
|
||||
// },
|
||||
// favorite: {
|
||||
// type: Boolean,
|
||||
// required: false,
|
||||
// default: false,
|
||||
// },
|
||||
// nickname: {
|
||||
// type: String,
|
||||
// required: false,
|
||||
// },
|
||||
// },
|
||||
// ],
|
||||
// otp: {
|
||||
// type: String,
|
||||
// default: null,
|
||||
// },
|
||||
// otpExpiration: {
|
||||
// type: Date,
|
||||
// default: null,
|
||||
// },
|
||||
|
||||
// transactions: {
|
||||
// type: Array,
|
||||
|
|
|
@ -5,6 +5,7 @@ import {
|
|||
deleteCollection,
|
||||
createCollection,
|
||||
updateCollection,
|
||||
updateCollectionByEndpoint,
|
||||
} from "../controllers/collection.js";
|
||||
import { verifyToken } from "../middleware/auth.js";
|
||||
import logApiCall from "../middleware/log.js";
|
||||
|
@ -26,20 +27,25 @@ router.get(
|
|||
router.post(
|
||||
"/create",
|
||||
// verifyToken,
|
||||
logApiCall,
|
||||
// logApiCall,
|
||||
createCollection
|
||||
);
|
||||
router.patch(
|
||||
"/update/:id",
|
||||
// verifyToken,
|
||||
logApiCall,
|
||||
// logApiCall,
|
||||
updateCollection
|
||||
);
|
||||
|
||||
router.patch(
|
||||
"/update/:id/endpoint",
|
||||
// verifyToken,
|
||||
// logApiCall,
|
||||
updateCollectionByEndpoint
|
||||
);
|
||||
router.delete(
|
||||
"/:id/delete",
|
||||
// verifyToken,
|
||||
logApiCall,
|
||||
// logApiCall,
|
||||
deleteCollection
|
||||
);
|
||||
|
||||
|
|
|
@ -28,20 +28,20 @@ router.get(
|
|||
router.post(
|
||||
"/create",
|
||||
// verifyToken,
|
||||
logApiCall,
|
||||
// logApiCall,
|
||||
createEndpoint
|
||||
);
|
||||
router.patch(
|
||||
"/update/:id",
|
||||
// verifyToken,
|
||||
logApiCall,
|
||||
// logApiCall,
|
||||
updateEndpoint
|
||||
);
|
||||
|
||||
router.delete(
|
||||
"/:id/delete",
|
||||
// verifyToken,
|
||||
logApiCall,
|
||||
// logApiCall,
|
||||
deleteEndpoint
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue