Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express');
- const router = express.Router();
- const multer = require('multer');
- const fs = require('fs');
- const request = require('request');
- const nodemailer = require('nodemailer');
- const { User } = require('../models/user');
- const { Reg } = require('../models/registeration');
- const { Company } = require('../models/company');
- const { Rating } = require('../models/rating');
- const { Category } = require('../models/category');
- const { Service } = require('../models/service');
- const { Tech } = require('../models/tech');
- const { Blog } = require('../models/blog');
- const { Review } = require('../models/review');
- const { Contact } = require('../models/contact');
- const { SubCat } = require('../models/subcategory');
- const { Portfolio } = require('../models/portfolio');
- const { Reference } = require('../models/reference');
- const { Solution } = require('../models/solution');
- const { GA } = require('../models/ga');
- const { BASE_URL } = require('../Config');
- var download = function(uri, filename, callback){
- request.head(uri, function(err, res, body){
- console.log('content-type:', res.headers['content-type']);
- console.log('content-length:', res.headers['content-length']);
- request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
- });
- };
- let OTP = [];
- const generateOTP = () => {
- let text = "";
- let possible = "0123456789";
- for (let i = 0; i < 6; i++)
- text += possible.charAt(Math.floor(Math.random() * possible.length));
- return text;
- }
- const sendMail = (toEmail, sub, msg) => {
- let transporter = nodemailer.createTransport({
- service: 'gmail',
- auth: {
- user: 'tecish.co@gmail.com',
- pass: 'PrateekMathur'
- }
- });
- let mailOptions = {
- from: 'tecish.co@gmail.com',
- to: toEmail,
- subject: sub,
- text: msg
- };
- transporter.sendMail(mailOptions, function(error, info){
- if (error) {
- return false;
- } else {
- return true;
- }
- });
- return true;
- }
- const StorageProfileImages = multer.diskStorage({
- // destination
- destination: (req, file, cb) => {
- cb(null, './public/ProfileImages');
- },
- filename: (req, file, cb) => {
- cb(null, Date.now()+'-'+file.originalname);
- }
- });
- // Multer Configuration
- const StorageBlogImage = multer.diskStorage({
- // destination
- destination: (req, file, cb) => {
- cb(null, './public/BlogImages');
- },
- filename: (req, file, cb) => {
- cb(null, Date.now()+'-'+file.originalname);
- }
- });
- const StorageLogo = multer.diskStorage({
- // destination
- destination: (req, file, cb) => {
- cb(null, './public/CompanyLogo');
- },
- filename: (req, file, cb) => {
- cb(null, Date.now()+'-'+file.originalname);
- }
- });
- // Multer Configuration
- const StoragePortfolio = multer.diskStorage({
- // destination
- destination: (req, file, cb) => {
- cb(null, './public/PortfolioImages');
- },
- filename: (req, file, cb) => {
- cb(null, Date.now()+'-'+file.originalname);
- }
- });
- const StorageSoluLogo = multer.diskStorage({
- // destination
- destination: (req, file, cb) => {
- cb(null, './public/SolutionLogo');
- },
- filename: (req, file, cb) => {
- cb(null, Date.now()+'-'+file.originalname);
- }
- });
- const uploadProfileImages = multer({storage: StorageProfileImages});
- const uploadBlogImage = multer({ storage: StorageBlogImage });
- const uploadCompanyLogo = multer({ storage: StorageLogo });
- const uploadPortfolioImage = multer({storage: StoragePortfolio});
- const uploadSolutionLogo = multer({ storage: StorageSoluLogo });
- router.get('/',(req,res) => {
- res.end('Welcome Admin');
- });
- // User Get and Add.
- router.get('/user',(req,res) => {
- User.find({}, (err, data) => {
- if(err) {
- res.send({"status":"error"});
- console.log(err);
- } else {
- res.send({data, ...{status: "ok"}});
- }
- })
- });
- router.get('/user/:userId',(req,res) => {
- User.find({_id: req.params.userId},(err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- } else {
- res.send({data, ...{status: "ok"}})
- }
- });
- });
- router.get('/reg',(req,res) => {
- Reg.find({}).populate('userId').exec((err, data) => {
- if(err) {
- res.send({"status":"error"});
- console.log(err);
- } else {
- res.send({data, ...{status: "ok"}});
- }
- });
- });
- router.get('/user/email/:email',(req,res) => {
- User.find({_id: req.params.email},(err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- } else {
- res.send({data, ...{status: "ok"}})
- }
- });
- });
- router.post("/user/add/linkedin",(req, res) => {
- const email = req.body.email;
- download(req.body.profilePicUrl, `./public/ProfileImages/${req.body.mobNo}.jpg`, function(){
- console.log('done');
- let user = new User({
- name: req.body.name,
- title: req.body.title,
- location: req.body.location,
- industry: req.body.industry,
- linkedinProfile: req.body.linkedinProfile,
- twitterProfile: req.body.twitterProfile,
- bio: req.body.bio,
- mobNo: req.body.mobNo,
- imgUrl: req.body.mobNo+'.jpg'
- });
- user.save().then((data) => {
- let response = data;
- let reg = new Reg({
- userId: data._id,
- email: req.body.email.toLowerCase(),
- pass: req.body.pass
- });
- reg.save().then((data) => {
- res.send({response, ...{status: "ok"}});
- sendMail(email,"Thanks for creating an account",`Your account has been created, your password is ${req.body.pass}`);
- }, (e) => {
- console.log('Error in email');
- User.findOneAndRemove({_id: response._id}, (err, data) => {
- console.log('inside rollback feature');
- if(err) {
- console.log({status: "error while performing rollback"});
- } else {
- console.log('Deleted successfully');
- }
- });
- if(e.name === "BulkWriteError")
- res.send({"status":"error","msg":"Email alredy taken"});
- else
- res.send({"status":"error", msg: "Something went Wrong"});
- return false;
- });
- }, (e) => {
- console.log(e);
- if(e.name === "BulkWriteError")
- res.send({"status":"error","msg":"mobile number alredy taken"});
- else
- res.send({"status":"error", msg: "SOmething went wrong"});
- return false;
- });
- });
- });
- // Data should be multipart/formdata encoded
- router.post("/user/add/form", uploadProfileImages.single('imgUrl'), (req, res) => {
- const email = req.body.email;
- let user = new User({
- name: req.body.name,
- title: req.body.title,
- location: req.body.location,
- industry: req.body.industry,
- linkedinProfile: req.body.linkedinProfile,
- twitterProfile: req.body.twitterProfile,
- bio: req.body.bio,
- mobNo: req.body.mobNo,
- imgUrl: req.file.name
- });
- user.save().then((data) => {
- let response = data;
- let reg = new Reg({
- userId: data._id,
- email: req.body.email.toLowerCase(),
- pass: req.body.pass
- });
- reg.save().then((data) => {
- res.send({response, ...{status: "ok"}});
- sendMail(email,"Thanks for creating an account",`Your account has been created, your password is ${req.body.pass}`);
- }, (e) => {
- console.log('Error in email');
- User.findOneAndRemove({_id: response._id}, (err, data) => {
- console.log('inside rollback feature');
- if(err) {
- console.log({status: "error while performing rollback"});
- } else {
- console.log('Deleted successfully');
- }
- });
- if(e.name === "BulkWriteError")
- res.send({"status":"error","msg":"Email alredy taken"});
- else
- res.send({"status":"error", msg: "Something went Wrong"});
- return false;
- });
- }, (e) => {
- console.log(e);
- if(e.name === "BulkWriteError")
- res.send({"status":"error","msg":"mobile number alredy taken"});
- else
- res.send({"status":"error", msg: "SOmething went wrong"});
- return false;
- });
- });
- });
- router.post("/user/edit", (req, res) => {
- const email = "";
- delete req.body.userId;
- let update = req.body;
- User.findOneAndUpdate({_id: req.body.userId}, {$set:update}, {new: true},(err, data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- } else {
- sendMail(email,"Information Updated","Updated successfully");
- res.send({data, ...{status: "ok"}})
- }
- });
- });
- router.post('/login', (req,res) => {
- Reg.find({$and: [{email: req.body.email},{pass: req.body.pass}]}, (err,data) => {
- if(err) {
- console.log(err);
- res.send({"status":"error"});
- return false;
- } else {
- if(data.length === 0) {
- // Failed Login
- res.json({
- login: false
- });
- } else {
- User.find({_id: data[0].userId}, (err, data) => {
- if(err) {
- console.log(err);
- res.send({"status":"error"});
- return false;
- }
- res.send({data, ...{status: "ok"}})
- });
- }
- }
- });
- });
- // Company Get and Add.
- router.get('/company',(req,res) => {
- Company.find({approved: true}).populate('userId').exec((err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- else res.send({data, ...{status: "ok"}})
- });
- });
- router.get('/company/all',(req,res) => {
- Company.find({}, (err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- else res.send({data, ...{status: "ok"}})
- });
- });
- router.post('/company/approve', (req, res) => {
- let update = {
- approved: true
- }
- Company.findOneAndUpdate({_id: req.body.companyId}, {$set:update}, {new: true},(err, data) => {
- if(err) {
- console.log(err);
- res.send({"status":"error"});
- return false;
- } else {
- res.send({data, ...{status: "ok"}})
- }
- });
- });
- router.post('/company/edit', (req, res) => {
- const id = req.body.companyId;
- delete req.body.companyId;
- let update = req.body;
- Company.findOneAndUpdate({_id: id}, {$set:update}, {new: true},(err, data) => {
- if(err) {
- console.log(err);
- res.send({"status":"error"});
- return false;
- } else {
- res.send({data, ...{status: "ok"}})
- }
- });
- });
- router.get('/company/:companyId',(req,res) => {
- Company.find({$and: [
- {_id: req.params.companyId},
- {approved: true}
- ]}).populate('userId').exec((err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- else res.send({data, ...{status: "ok"}})
- });
- });
- router.post("/company/add", uploadCompanyLogo.single('logo') ,(req, res) => {
- let email = "";
- Reg.find({userId: req.body.userId}, (err, data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- email = data[0].email;
- let company = new Company({
- userId: req.body.userId,
- name: req.body.name,
- ownerName: req.body.ownerName,
- logo: req.file.filename,
- tagline: req.body.tagline,
- founded: req.body.founded,
- noOfEmp: req.body.noOfEmp,
- minProjectPrice: req.body.minProjectPrice,
- avgPricePerHour: req.body.avgPricePerHour,
- websiteLink: req.body.websiteLink,
- emailTechSupport: req.body.emailTechSupport,
- emailAdmin: req.body.emailAdmin,
- twitterProfile: req.body.twitterProfile,
- facebookProfile: req.body.facebookProfile,
- summary: req.body.summary,
- client: req.body.client,
- country: req.body.country || "",
- street: req.body.street,
- city: req.body.city || "",
- state: req.body.state || "",
- postalCode: req.body.postalCode,
- mobNo: req.body.mobNo,
- cert: req.body.cert,
- accolades: req.body.accolades,
- detailedDes: req.body.detailedDes,
- services: req.body.services,
- tech: req.body.tech,
- approved: false
- });
- company.save().then((data) => {
- res.send({data, ...{status: "ok"}})
- sendMail(email,"Company under approval","Your company will be verified and updated in 48 hours");
- }, (e) => {
- res.send({"status":"error"});
- return false;
- });
- });
- });
- // Rating Get and Add.
- router.get('/rating',(req,res) => {
- Rating.find({}, (err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- else res.json({data, ...{status: "ok"}});
- });
- });
- router.get('/rating/:catId',(req,res) => {
- Rating.find({}).populate('company_id').exec((err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- else {
- let result = [];
- for(let i=0; i < data.length; i++) {
- if(req.params.catId in JSON.parse(data[i].ratingList)) {
- result.push(data[i]);
- }
- }
- res.send(result);
- }
- });
- });
- router.post("/rating/add", (req, res) => {
- const company_id = req.body.company_id || null;
- const solution_id = req.body.solution_id || null;
- const type = req.body.type;
- const userId = req.body.userId;
- if('company_id' in req.body)
- delete req.body.company_id;
- if('solution_id' in req.body)
- delete req.body.solution_id;
- delete req.body.type;
- delete req.body.userId;
- let rating = new Rating({
- company_id: company_id,
- solution_id: solution_id,
- type: type,
- userId: userId,
- ratingList: JSON.stringify(req.body)
- });
- rating.save().then((data) => {
- if(type == "Company".toLowerCase())
- res.send({data, ...{status: "ok"}})
- else
- res.send({data, ...{status: "ok"}})
- }, (e) => {
- res.send({"status":"error"});
- return false;
- });
- });
- // Category Get and Add.
- router.get('/category', (req,res) => {
- Category.find({}, (err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- else res.send({data, ...{status: "ok"}})
- });
- });
- router.get('/category/:categoryId',(req,res) => {
- // res.end(req.params.categoryId);
- Category.find({_id: req.params.categoryId}, (err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- else res.send({data, ...{status: "ok"}})
- });
- });
- router.post("/category/add", (req, res) => {
- console.log(req.body);
- let category = new Category({
- name: req.body.name
- });
- category.save().then((data) => {
- res.send({data, ...{status: "ok"}})
- }, (e) => {
- res.send({"status":"error"});
- return false;
- });
- });
- // Service Get and Add.
- router.get('/service', (req,res) => {
- Service.find({}, (err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- else res.send({data, ...{status: "ok"}})
- });
- });
- router.get('/service/:serviceId',(req,res) => {
- Service.find({_id: req.params.serviceId}, (err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- else res.send({data, ...{status: "ok"}})
- });
- });
- router.post("/service/add", (req, res) => {
- console.log(req.body);
- let service = new Service({
- name: req.body.name
- });
- Service.save().then((data) => {
- res.send({data, ...{status: "ok"}})
- }, (e) => {
- res.send({"status":"error"});
- return false;
- });
- });
- router.post("/service/approve", (req, res) => {
- let update = {
- approved: true
- }
- Service.findOneAndUpdate({_id: req.body.serviceId}, {$set:update}, {new: true},(err, data) => {
- if(err) {
- console.log(err);
- res.send({"status":"error"});
- return false;
- } else {
- res.send({data, ...{status: "ok"}})
- }
- });
- });
- router.post('/service/edit', (req, res) => {
- const id = req.body.serviceId;
- delete req.body.serviceId;
- let update = req.body;
- Service.findOneAndUpdate({_id: id}, {$set:update}, {new: true},(err, data) => {
- if(err) {
- console.log(err);
- res.send({"status":"error"});
- return false;
- } else {
- res.send({data, ...{status: "ok"}})
- }
- });
- });
- router.get('/tech', (req,res) => {
- Tech.find({}, (err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- else res.send({data, ...{status: "ok"}})
- });
- });
- router.get('/tech/:techId',(req,res) => {
- Tech.find({_id: req.params.techId}, (err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- else res.send({data, ...{status: "ok"}})
- });
- });
- router.post("/tech/add", (req, res) => {
- console.log(req.body);
- let tech = new Tech({
- name: req.body.name
- });
- tech.save().then((data) => {
- res.send({data, ...{status: "ok"}})
- }, (e) => {
- res.send({"status":"error"});
- return false;
- });
- });
- // Review Get and Add.
- router.get('/review', (req,res) => {
- Review.find({approved: true}, (err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- res.json({data, ...{status: "ok"}});
- });
- });
- router.get('/review/all', (req,res) => {
- Review.find({}, (err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- res.json({data, ...{status: "ok"}});
- });
- });
- router.get('/review/company/:companyId', (req,res) => {
- Review.find({$and: [
- {companyId: req.params.companyId},
- {approved: true},
- ]}, (err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- let items = 0;
- let total = 0;
- data = data.map(item => {
- items++;
- total += item.rating.overallRating.rating;
- return item;
- });
- let obj = {reviewsArray:data, avgRating: total/items}
- res.send(obj);
- });
- });
- router.get('/review/company/filter', (req,res) => {
- let mySort = {};
- if(id === 1)
- mySort = {updatedAt: -1}
- if(id === 2)
- mySort = {rating: {overallRating: {rating: 1}}}
- if(id === 3)
- mySort = {rating: {overallRating: {rating: -1}}}
- Review.find({$and: [
- {companyId: req.params.companyId},
- {approved: true},
- ]},[],{sort: mySort},(err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- let items = 0;
- let total = 0;
- data = data.map(item => {
- items++;
- total = item.rating.overallRating.rating;
- return item;
- });
- let obj = {reviewsArray:data, avgRating: total/items}
- res.send(obj);
- });
- });
- router.get('/review/filter', (req,res) => {
- let mySort = {};
- if(id === 1)
- mySort = {updatedAt: -1}
- if(id === 2)
- mySort = {rating: {overallRating: {rating: 1}}}
- if(id === 3)
- mySort = {rating: {overallRating: {rating: -1}}}
- Review.find({$and: [
- {companyId: req.params.companyId},
- {approved: true},
- ]},[],{sort: mySort},(err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- let items = 0;
- let total = 0;
- data = data.filter(item => {
- items++;
- total = item.rating.overallRating.rating;
- return parseInt(item.cost) > parseInt(req.query.cost);
- });
- let obj = {reviewsArray:data, avgRating: total/items}
- res.send(obj);
- });
- });
- router.get('/review/:userId', (req,res) => {
- // res.end(req.params.reviewId);
- Review.find({$and: [
- {userId: req.params.userId},
- {approved: true},
- ]}).populate('companyId').exec((err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- if(data.length === 0) res.json({success:false});
- else res.json({...{success: true}, data});
- });
- });
- router.post("/review/add", (req, res) => {
- const email = req.body.email;
- let review = new Review({
- companyId: req.body.companyId,
- typeOfProject: req.body.typeOfProject,
- projectTitle: req.body.projectTitle,
- industry: req.body.industry,
- cost: req.body.cost,
- startDate: req.body.startDate,
- endDate: req.body.endDate,
- userId: req.body.userId,
- background: req.body.background,
- challenge: {
- service: req.body.cService,
- goal: req.body.cGoal
- },
- solution: {
- vendor: req.body.vendor,
- projectDetail: req.body.projectDetail,
- teamComposition: req.body.teamComposition
- },
- result: {
- outcome: req.body.outcome,
- effective: req.body.effective,
- keyFeature: req.body.keyFeature,
- improvements: req.body.improvements
- },
- rating: {
- quality: {
- rating: req.body.qRating,
- detail: req.body.qDetail
- },
- schedule: {
- rating: req.body.sRating,
- detail: req.body.sDetail
- },
- cost: {
- rating: req.body.cRating,
- detail: req.body.cDetail
- },
- refer: {
- rating: req.body.rRating,
- detail: req.body.rDetail
- },
- overallRating: {
- rating: req.body.oRating,
- detail: req.body.oDetail
- }
- },
- reviewer: {
- fullName: req.body.fullName,
- position: req.body.position,
- companyName: req.body.companyName,
- companySize: req.body.companySize,
- country: req.body.country,
- email: req.body.email,
- mobNo: req.body.mobNo
- },
- approved: false
- });
- review.save().then((data) => {
- res.send({data, ...{status: "ok"}})
- sendMail(email,"Review Under approval","Your review will be updated in 48 hours");
- }, (e) => {
- res.send({"status":"error"});
- return false;
- });
- });
- // Subcategory
- router.get('/subcategory', (req,res) => {
- SubCat.find({}).populate('cat_id').exec((err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- else res.json({data, ...{status: "ok"}});
- });
- });
- router.post('/subcategory/add', (req,res) => {
- let subcat = new SubCat({
- cat_id: req.body.cat_id,
- name: req.body.name
- });
- subcat.save().then((data) => {
- res.json({data, ...{status: "ok"}});
- }, (e) => {
- res.send({"status":"error"});
- return false;
- });
- });
- router.get('/portfolio', (req,res) => {
- Portfolio.find({}, (err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- else res.send({data, ...{status: "ok"}})
- });
- });
- router.post("/portfolio/add", uploadPortfolioImage.single('img') ,(req, res) => {
- let portfolio = new Portfolio({
- userId: req.body.userId,
- title: req.body.title,
- companyId: req.body.companyId,
- description: req.body.description,
- imageName : req.file.filename
- });
- portfolio.save().then((data) => {
- res.send({data, ...{status: "ok"}})
- }, (e) => {
- res.send({"status":"error"});
- return false;
- });
- });
- router.get('/portfolio/:companyId',(req,res) => {
- Portfolio.find({companyId: req.params.companyId}, (err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- else res.send({data, ...{status: "ok"}})
- });
- });
- // Reference
- router.get('/reference', (req,res) => {
- Reference.find({}, (err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- else res.json({data, ...{status: "ok"}});
- });
- });
- router.get('/reference/user/:userId',(req,res) => {
- Reference.find({userId: req.params.userId}, (err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- else res.send({data, ...{status: "ok"}})
- });
- });
- router.post("/reference/add",(req, res) => {
- let reference = new Reference({
- userId: req.body.userId,
- companyId: req.body.companyId,
- fName: req.body.fName,
- lName: req.body.lName,
- company: req.body.company,
- positionAtCompany: req.body.positionAtCompany,
- mobNo: req.body.mobNo,
- email: req.body.email,
- city: req.body.city,
- country: req.body.country,
- projectCost: req.body.projectCost,
- projectLength: req.body.projectLength,
- projectDescription: req.body.projectDescription
- });
- reference.save().then((data) => {
- res.send({data, ...{status: "ok"}})
- }, (e) => {
- res.send({"status":"error"});
- return false;
- });
- });
- router.get('/solution/all', (req,res) => {
- Solution.find({}, (err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- res.json({data, ...{status: "ok"}});
- })
- });
- router.get('/solution', (req,res) => {
- Solution.find({approved: true}, (err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- res.json({data, ...{status: "ok"}});
- })
- });
- router.post("/solution/add", uploadSolutionLogo.single('logo') ,(req, res) => {
- let solu = new Solution({
- userId: req.body.userId,
- name: req.body.name,
- softwareCat: req.body.softwareCat,
- logo: req.file.filename,
- tagline: req.body.tagline,
- des: req.body.des,
- softwareSummary: req.body.softwareSummary,
- noOfEmp: req.body.noOfEmp,
- introText: req.body.introText,
- optionToStart: req.body.optionToStart,
- websiteLink: req.body.websiteLink,
- client: req.body.client,
- priceRange: req.body.priceRange,
- pricingOptions: req.body.pricingOptions,
- summary: req.body.summary,
- pricingPage: req.body.pricingPage,
- services: req.body.services,
- approved: false
- });
- solu.save().then((data) => {
- res.send({data, ...{status: "ok"}})
- }, (e) => {
- res.send({"status":"error"});
- return false;
- });
- });
- // Google Analytics Get and Add.
- router.get('/ga', (req,res) => {
- GA.find({}, (err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- else res.send({data, ...{status: "ok"}})
- });
- });
- router.post("/ga/add", (req, res) => {
- let ga = new GA({
- companyId: req.body.company_id,
- details: req.body.details
- });
- ga.save().then((data) => {
- res.send({data, ...{status: "ok"}})
- }, (e) => {
- res.send({"status":"error"});
- return false;
- });
- });
- router.get('/search', (req,res) => {
- // Search Company and
- Company.find({
- $and: [
- {$or: [
- {name: { "$regex": req.body.name, "$options": "i" }},
- {services: {"$regex": req.body.name, "$options": "i" }},
- {tech: {"$regex": req.body.name, "$options": "i" }},
- ]},
- {approved: true}
- ]}, (err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- else res.json({data, ...{status: "ok"}});
- });
- });
- router.get('/company/user/:userId', (req, res) => {
- Company.find({$and: [
- {userId: req.params.userId},
- {approved: true},
- ]}, (err, data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- else res.send({data, ...{status: "ok"}})
- });
- });
- router.post('/user/forget', (req, res) => {
- const givenEmail = req.body.email.toLowerCase();
- Reg.find({email: givenEmail}, (err, data) => {
- if( err ) {
- res.send({"status":"error"});
- return false;
- }
- if(data.length !== 1) {
- res.send({"status":"No such file exists"});
- return false;
- }
- let regId = data[0]._id;
- let otp = generateOTP();
- let transporter = nodemailer.createTransport({
- service: 'gmail',
- auth: {
- user: 'tecish.co@gmail.com',
- pass: 'PrateekMathur'
- }
- });
- let mailOptions = {
- from: 'tecish.co@gmail.com',
- to: givenEmail,
- subject: 'OTP for Tecish',
- text: `Your OTP for password reset request is: ${otp}`
- };
- transporter.sendMail(mailOptions, function(error, info){
- if (error) {
- console.log(error);
- } else {
- console.log('Email sent: ' + info.response);
- OTP.push(
- {
- regId: regId,
- email: req.body.email,
- otp: otp
- }
- );
- console.log("inside",OTP);
- res.send({status:"SENT", otp: OTP});
- }
- });
- });
- });
- router.post('/user/verify/otp', (req, res) => {
- const result = OTP.filter((instance) => {
- return instance.otp === req.body.otp;
- });
- if (result.length === 1) {
- res.json({"success": true,"regId" : result[0].regId});
- } else {
- res.json({"success": false});
- }
- });
- router.post('/user/change/password', (req, res) => {
- Reg.findOneAndUpdate({_id: req.body.regId}, {$set:{pass:req.body.pass}}, {new: true}, function(err, data){
- if(err){
- res.send({"status":"error"});
- return false;
- }
- res.send({data, ...{status: "ok"}})
- });
- });
- router.get('/company/service/:service', (req, res) => {
- const result = [];
- Company.find({approved: true}, (err, data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- else {
- data.map(row => {
- let servicesArray = row.services.split(',');
- if(servicesArray.includes(req.params.service)) {
- result.push(row);
- }
- });
- res.send(result);
- }
- })
- });
- router.get('/company/name', (req, res) => {
- Company.find({approved: true},'name',(err, data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- else res.send({data, ...{status: "ok"}})
- });
- });
- router.post('/filter', (req, res) => {
- Company.find({
- $and: [
- {$or: [
- {name: { "$regex": req.body.name, "$options": "i" }},
- {services: {"$regex": req.body.name, "$options": "i" }},
- {tech: {"$regex": req.body.name, "$options": "i" }},
- ]},
- {approved: true}
- ]}, (err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- else {
- data = data.filter(company => {
- const minPrice = parseInt(company.minProjectPrice);
- const emp = parseInt(company.noOfEmp);
- const hourPrice = parseInt(company.avgPricePerHour);
- let flag = true;
- const serviceArray = company.services.split(',');
- if(req.body.industryFocus.length !== 1) {
- flag = false;
- serviceArray.map(item => {
- if(req.body.industryFocus.includes(item)) {
- flag = true;
- }
- });
- }
- return flag && minPrice >= parseInt(req.body.minPrice) && hourPrice >= parseInt(req.body.hourPrice) && emp >= parseInt(req.body.emp);
- });
- res.send({data, ...{status: "ok"}})
- }
- }
- );
- });
- router.get('/leader/matrix',(req, res) => {
- Company.find({approved: true},[],{skip: 0, last:10}).populate('userId').exec((err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- else res.send({data, ...{status: "ok"}})
- });
- });
- router.get('/blog', (req, res) => {
- Blog.find({}).populate('category').exec((err,data) => {
- if(err) {
- res.send({status: "error"});
- return;
- } else {
- res.send({data, ...{status: "ok"}})
- }
- })
- });
- // Category here means serivce
- router.get('/blog/:categoryId', (req, res) => {
- Blog.find({category: req.params.categoryId}).populate('category').exec((err,data) => {
- if(err) {
- res.send({status: "error"});
- return;
- } else {
- res.send({data, ...{status: "ok"}})
- }
- })
- });
- router.post("/blog/add", uploadCompanyLogo.single('img') ,(req, res) => {
- let blog = new Blog({
- title: req.body.title,
- img: req.body.img,
- content: req.body.content,
- date: req.body.date,
- category: req.body.category
- });
- blog.save().then((data) => {
- res.send({data, ...{status: "ok"}})
- }, (e) => {
- res.send({"status":"error"});
- return false;
- });
- });
- router.get('/ contact', (req,res) => {
- Contact.find({}, (err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- else res.send({data, ...{status: "ok"}})
- });
- });
- router.get('/contact/:contactId',(req,res) => {
- // res.end(req.params.contactId);
- Contact.find({_id: req.params.contactId}, (err,data) => {
- if(err) {
- res.send({"status":"error"});
- return false;
- }
- else res.send({data, ...{status: "ok"}})
- });
- });
- router.post("/contact/add", (req, res) => {
- console.log(req.body);
- let contact = new Contact({
- name: req.body.name
- });
- contact.save().then((data) => {
- res.send({data, ...{status: "ok"}})
- }, (e) => {
- res.send({"status":"error"});
- return false;
- });
- });
- module.exports = router;
Add Comment
Please, Sign In to add comment