Yalla-Feen:使用Node js的Yalla Feen后端

  • l7_458860
    了解作者
  • 559.6KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-14 04:29
    上传日期
Yalla-Feen:使用Node js的Yalla Feen后端
Yalla-Feen-main.zip
  • Yalla-Feen-main
  • models
  • category_model.js
    639B
  • user_model.js
    2.9KB
  • rating_model.js
    487B
  • place_model.js
    1.9KB
  • tags_model.js
    325B
  • comment_model.js
    329B
  • package.json
    1017B
  • swagger.json
    4KB
  • uploads
  • place
  • avatar-1612321495401.jpg
    82.2KB
  • images-1612454038675.0
    103.2KB
  • images-1612722104724.jpg
    9.5KB
  • images-1612722104721.jpg
    112.4KB
  • user
  • avatar.jpg
    43.9KB
  • avatar-1612321809268.png
    1.5KB
  • avatar-1612807761905.jpg
    82.2KB
  • avatar-1612807802502.jpg
    43.9KB
  • avatar-1612807733057.jpg
    82.2KB
  • routes
  • category_routes.js
    484B
  • rating_routes.js
    529B
  • placeRoutes.js
    1.9KB
  • user_routes.js
    1.3KB
  • commentRoutes.js
    523B
  • favorite_routes.js
    878B
  • tags_routes.js
    450B
  • middleware
  • authMiddleware.js
    2.2KB
  • upload.js
    1KB
  • validationBody.js
    447B
  • package-lock.json
    36.2KB
  • controllers
  • rating_controllers.js
    1.7KB
  • tags_controllers.js
    1.7KB
  • category_controllers.js
    1.8KB
  • user_contoller.js
    5.3KB
  • commentControllers.js
    2.4KB
  • favorite_controller.js
    1.7KB
  • place_controllers.js
    12.7KB
  • validation-schema
  • user.js
    504B
  • place.js
    297B
  • d
    1KB
  • roles.js
    408B
  • .gitignore
    1.8KB
  • app.js
    2.4KB
  • utils
  • sendmail.js
    566B
  • egypt_city_lang_lat.js
    360B
内容介绍
// joi const Place = require("../models/place_model"); const Comment = require("../models/comment_model"); const Category = require("../models/category_model"); const Rating = require("../models/rating_model"); const upload = require("../middleware/upload").upload; const Tags = require("../models/tags_model"); const placeImageUrl = require('dotenv').config().parsed.PLACEIMAGESURL; // const { find } = require("../models/place_model"); // const { randomBytes } = require("crypto"); const Nominatim = require('nominatim-geocoder'); const { Mongoose } = require("mongoose"); const geocoder = new Nominatim() const addPlace = (req, res) => { upload.array('images', 12)(req, res, async function (err) { if (err) { return res.status(400).send({ success: false, message: "allowed files are images and size 2mb and max-files 12 image" }) } const body = JSON.parse(JSON.stringify(req.body)); if (!body) { return res.status(400).json({ success: false, error: "You must add place", }); } // console.log(req.files); const category = await Category.findOne({ 'title': body.category }) if (!category) { res.send({ success: false, error: "category not found" }) } body.category = category._id const place = new Place(body); if (!place) { return res.status(400).json({ success: false, error: err }); } if (!body.location) { await geocoder.search({ q: place.title }) .then((response) => { // data = console.log(response); place.location.coordinates = [parseFloat(response[0].lon), parseFloat(response[0].lat) ] }) .catch((error) => { err = error; }) console.log(place.location.coordinates); } if (req.files) { for (item of req.files) { place.images.push(placeImageUrl + item.filename); } } console.log(place); place.owner = req.user._id; place .save() .then(async (data) => { category.places.push(data._id); await category.save() return res.status(200).json({ success: true, id: place._id, message: "Place item created", }); }) .catch((error) => { return res.status(400).json({ error, message: "Place item not created", }); }) }) }; const getAllPlaces = async (req, res) => { await Place.find({}).populate({ path: 'owner', select: 'username' }).populate({ path: 'comments', select: 'text', populate: { path: "user", select: "username" } }).populate({ path: 'category', select: "title" }).populate({ path: 'tags', select: 'title' }).exec((err, places) => { if (err) { return res.status(400).send({ success: false, error: err }); } if (!places.length) { return res.status(404).send({ success: false, error: `Place not found` }); } return res.status(200).send({ success: true, data: places }); }); }; const getOwnerPlaces = async (req, res) => { await Place.find({ 'owner': req.user._id }, (err, places) => { // console.log(req.user._id); if (err) { res.send({ success: false, err }) } res.send({ places }) }).populate({ path: 'comments', select: ['text', 'createdAt'], populate: { path: "user", select: "username" } }).populate().exec() } const getPlaceDetails = async (req, res) => { // console.log('im in place details'); const result = await Place.findById(req.params.id).populate({ path: 'comments', select: ['text', 'createdAt'], populate: { path: "user", select: ["username", "avatar"] } }).populate().exec(); res.send(result); }; const placeSearch = async (req, res) => { // console.log('im in place details'); title = req.params.title.toLowerCase(); const result = await Place.findOne({ 'title': { "$regex": title } }).populate({ path: 'comments', select: ['text', 'createdAt'], populate: { path: "user", select: ["username", "avatar"] } }).populate().exec(); if (!result) { res.status(404).send({ success: false, message: "place not found" }) } res.send({ success: true, id: result._id }); }; const customFilter = async (req, res) => { const { category, tagTitle } = req.params; const tag = await Tags.findOne({ 'title': tagTitle }) .catch() const result = await Category .find({ 'title': category }) .populate({ path: 'places', select: ['title', 'description'], match: { 'tags': { "$in": [tag._id, ] } }, populate: { path: 'tags', select: "title" } }) .exec() if (result.length == 0) { res.send({ success: false, message: "Sorry not found yet" }) } res.send({ success: true, message: "founded", data: result, tag: tag }) } const customSearch = async (req, res) => { let {category,tag,city = '',budget = 100, type=['solo','family','couples','friends']} = req.query let _tag = await Tags.findOne({'title': {'$regex':tag}}) if(!_tag){ _tag = {_id:"601c0abfe834ce2f70c29450"} } budget = parseInt(budget) budget =(budget > 0 )?parseInt(budget):100; // console.log(budget); const result = await Category .find({ 'title': category }) .populate({ path: 'places', select: ['title', 'city','minBudget','type'], match: { 'tags': { "$in": [_tag._id, ] }, 'city':{'$regex':city}, 'minBudget':{'$lt':budget}, 'type':{"$in":type} }, populate: { path: 'tags', select: "title" } }) .exec() if (result.length == 0) { res.send({ success: false, message: "Sorry not found yet" }) } res.send({success: true,message: "founded", data: result,tag: tag}) } // //stash // const searchByRating = async (req, res) => { // // console.log('im in place details'); // const result = await Place.findOne({:req.params.rating}).populate({ // path:'comments', // select:['text','createdAt'], // populate:{ // path:"user", // select:["username","avatar"]} // }).populate().exec(); // if(!result){ // res.status(404).send({success:false,message:"place not found"}) // } // res.send({success:true,id:result._id}); // }; // // const updatePlace = async (req, res) => { await Place.findByIdAndUpdate( req.params.id, req.body, { new: true }, (err, place) => { if (err) { return res.status(500).send({ success: false, message: err }); } res.send({ success: true, message: place }) } ) res.send(req.place); }; const deletePlace = (req, res) => { Place.findByIdAndDelete(req.params.id) .then((data) => { if (!data) { res.send({ succes: false, message: "place not found" }) } res.send({ succes: true, message: "place deleted", data: data }) }) .catch(err => { res.send({ succes: false, error: err }) }); } const addCommentToPlace = async (req, res) => { const place = await Place.findById(req.params.id).catch( err => res.send({ success: false, message: "place not exist" } )); const body = req.body; if (!body) { return res.status(400).json({ success: false, error: "You must add comment", }); } const comment = new Comment(body); if (!comment) {
评论
    相关推荐
    • 后端
      后端
    • 后端
      后端 云功能教程
    • 后端
      后端
    • 后端
      后端
    • 后端
      非洲观察
    • 后端
      ●●●● 后端 后端 有助于 如果您想知道如何为该项目做贡献,请参阅 执照 版权所有@ 2019-2020 dahliaOS作者 该项目根据
    • 后端
      Patena后端
    • 后端
      鲨鱼 如果要构建自己的SHAK ,请转到Front-End的readme.md文件:
    • 后端
      后端
    • 后端
      后端