├── .gitignore ├── .env ├── src ├── db │ └── mongodb.js ├── router │ ├── bg.router.js │ ├── pdp.router.js │ ├── plp.router.js │ ├── category.router.js │ ├── editorial.router.js │ ├── header.router.js │ ├── product.router.js │ ├── productF.router.js │ ├── editoril.router.js │ ├── productreco.router.js │ ├── bookmark.router.js │ └── users.router.js ├── schema │ ├── bgImage.schema.js │ ├── category.schema.js │ ├── plp.schema.js │ ├── header.schema.js │ ├── editoril.schema.js │ ├── productreco.schema.js │ ├── editorial.schema.js │ ├── product-feature.schema.js │ ├── pdp.schema.js │ ├── users.schema.js │ ├── bookmark.schema.js │ └── product.schema.js ├── model │ ├── pdp.model.js │ ├── plp.modul.js │ ├── bg.modul.js │ ├── header.model.js │ ├── users.modul.js │ ├── category.modal.js │ ├── editoril.modal.js │ ├── editorial.modal.js │ ├── products.model.js │ ├── product.model.js │ ├── product-features.model.js │ └── bookmark.model.js ├── server.js └── controller │ ├── plp.contr.js │ ├── bg.contr.js │ ├── category.contr.js │ ├── header.contr.js │ ├── productreco.contr.js │ ├── productF.contr.js │ ├── editoril.contr.js │ ├── pdp.contr.js │ ├── editorial.contr.js │ ├── users.contr.js │ ├── product.contr.js │ └── bookmarl.contr.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules -------------------------------------------------------------------------------- /.env: -------------------------------------------------------------------------------- 1 | PORT = 5500 2 | DB = mongodb+srv://academytalaba:STMWTCOlFp9UWf7y@cluster0.qy2z4ss.mongodb.net/dgregory 3 | EMAIL = mrHuman 4 | PASSWORD = 1234 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/db/mongodb.js: -------------------------------------------------------------------------------- 1 | import mongoose from "mongoose"; 2 | import dotenv from "dotenv"; 3 | dotenv.config(); 4 | mongoose 5 | .connect(process.env.DB) 6 | .then(console.log("connection")) 7 | .catch((er) => console.log(er.message)); -------------------------------------------------------------------------------- /src/router/bg.router.js: -------------------------------------------------------------------------------- 1 | import { Router } from "express"; 2 | import head from "../controller/bg.contr.js"; 3 | 4 | const bgRouter = Router(); 5 | 6 | bgRouter 7 | .get("/", head.get) 8 | .get("/:id", head.get) 9 | .post("/", head.post) 10 | .put("/:id", head.put) 11 | .delete("/:id", head.delete); 12 | 13 | export default bgRouter; -------------------------------------------------------------------------------- /src/router/pdp.router.js: -------------------------------------------------------------------------------- 1 | import { Router } from "express"; 2 | import head from "../controller/pdp.contr.js"; 3 | 4 | const pdpRouter = Router(); 5 | 6 | pdpRouter 7 | .get("/", head.get) 8 | .get("/:id", head.get) 9 | .post("/", head.post) 10 | .put("/:id", head.put) 11 | .delete("/:id", head.delete); 12 | 13 | export default pdpRouter; -------------------------------------------------------------------------------- /src/router/plp.router.js: -------------------------------------------------------------------------------- 1 | import { Router } from "express"; 2 | import head from "../controller/plp.contr.js"; 3 | 4 | const plpRouter = Router(); 5 | 6 | plpRouter 7 | .get("/", head.get) 8 | .get("/:id", head.get) 9 | .post("/", head.post) 10 | .put("/:id", head.put) 11 | .delete("/:id", head.delete); 12 | 13 | export default plpRouter; -------------------------------------------------------------------------------- /src/router/category.router.js: -------------------------------------------------------------------------------- 1 | import { Router } from "express"; 2 | import head from "../controller/category.contr.js"; 3 | 4 | const catRouter = Router(); 5 | 6 | catRouter 7 | .get("/", head.get) 8 | .get("/:id", head.get) 9 | .post("/", head.post) 10 | .put("/:id", head.put) 11 | .delete("/:id", head.delete); 12 | 13 | export default catRouter; -------------------------------------------------------------------------------- /src/router/editorial.router.js: -------------------------------------------------------------------------------- 1 | import { Router } from "express"; 2 | import head from "../controller/editorial.contr.js"; 3 | 4 | const editRouter = Router(); 5 | 6 | editRouter 7 | .get("/", head.get) 8 | .get("/:id", head.get) 9 | .post("/", head.post) 10 | .put("/:id", head.put) 11 | .delete("/:id", head.delete); 12 | 13 | export default editRouter; -------------------------------------------------------------------------------- /src/router/header.router.js: -------------------------------------------------------------------------------- 1 | import { Router } from "express"; 2 | import head from "../controller/header.contr.js"; 3 | 4 | const headerRouter = Router(); 5 | 6 | headerRouter 7 | .get("/", head.get) 8 | .get("/:id", head.get) 9 | .post("/", head.post) 10 | .put("/:id", head.put) 11 | .delete("/:id", head.delete); 12 | 13 | export default headerRouter; -------------------------------------------------------------------------------- /src/router/product.router.js: -------------------------------------------------------------------------------- 1 | import { Router } from "express"; 2 | import head from "../controller/product.contr.js"; 3 | 4 | const productRouter = Router(); 5 | 6 | productRouter 7 | .get("/", head.get) 8 | .get("/:id", head.get) 9 | .post("/", head.post) 10 | .put("/:id", head.put) 11 | .delete("/:id", head.delete); 12 | 13 | export default productRouter; -------------------------------------------------------------------------------- /src/router/productF.router.js: -------------------------------------------------------------------------------- 1 | import { Router } from "express"; 2 | import head from "../controller/productF.contr.js"; 3 | 4 | const productRouter = Router(); 5 | 6 | productRouter 7 | .get("/", head.get) 8 | .get("/:id", head.get) 9 | .post("/", head.post) 10 | .put("/:id", head.put) 11 | .delete("/:id", head.delete); 12 | 13 | export default productRouter; -------------------------------------------------------------------------------- /src/router/editoril.router.js: -------------------------------------------------------------------------------- 1 | import { Router } from "express"; 2 | import head from "../controller/editoril.contr.js"; 3 | 4 | const editorilRouter = Router(); 5 | 6 | editorilRouter 7 | .get("/", head.get) 8 | .get("/:id", head.get) 9 | .post("/", head.post) 10 | .put("/:id", head.put) 11 | .delete("/:id", head.delete); 12 | 13 | export default editorilRouter; -------------------------------------------------------------------------------- /src/router/productreco.router.js: -------------------------------------------------------------------------------- 1 | import { Router } from "express"; 2 | import head from "../controller/productreco.contr.js"; 3 | 4 | const productrecoRouter = Router(); 5 | 6 | productrecoRouter 7 | .get("/", head.get) 8 | .get("/:id", head.get) 9 | .post("/", head.post) 10 | .put("/:id", head.put) 11 | .delete("/:id", head.delete); 12 | 13 | export default productrecoRouter; -------------------------------------------------------------------------------- /src/router/bookmark.router.js: -------------------------------------------------------------------------------- 1 | import { Router } from "express"; 2 | import head from "../controller/bookmarl.contr.js"; 3 | 4 | const bookMRouter = Router(); 5 | 6 | bookMRouter 7 | .get("/", head.get) 8 | .get("/:id", head.get) 9 | .post("/", head.post) 10 | .post("/buy/:id", head.buy) 11 | .put("/:id", head.put) 12 | .delete("/:id", head.delete); 13 | 14 | export default bookMRouter; 15 | -------------------------------------------------------------------------------- /src/router/users.router.js: -------------------------------------------------------------------------------- 1 | import { Router } from "express"; 2 | import head from "../controller/users.contr.js"; 3 | 4 | const bgRouter = Router(); 5 | 6 | bgRouter 7 | 8 | .get("/", head.get) 9 | .get("/:id", head.get) 10 | // .post("/admin", head.adminLogin) 11 | .post("/login", head.login) 12 | .post("/register", head.register) 13 | .put("/:id", head.put) 14 | .delete("/:id", head.delete); 15 | 16 | export default bgRouter; 17 | -------------------------------------------------------------------------------- /src/schema/bgImage.schema.js: -------------------------------------------------------------------------------- 1 | import { Schema, model, Types } from "mongoose"; 2 | const bgSchema = new Schema( 3 | { 4 | 5 | 6 | imageLink: { 7 | type: String, 8 | required: true, 9 | }, 10 | 11 | }, 12 | { 13 | timestamps: { 14 | createdAt: "create_at", 15 | deletedAt: "delete_at", 16 | }, 17 | } 18 | ); 19 | 20 | export default model("bgImage", bgSchema); 21 | -------------------------------------------------------------------------------- /src/schema/category.schema.js: -------------------------------------------------------------------------------- 1 | import { Schema, model, Types } from "mongoose"; 2 | const categorySchema = new Schema( 3 | { 4 | 5 | cat_name: { 6 | type: String, 7 | required: true 8 | }, 9 | 10 | }, 11 | { 12 | timestamps: { 13 | createdAt: "create_at", 14 | deletedAt: "delete_at", 15 | }, 16 | } 17 | ); 18 | 19 | export default model("category", categorySchema); 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dgregory-figma", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "type": "module", 7 | "scripts": { 8 | "start": "node src/server.js", 9 | "dev": "nodemon src/server.js" 10 | }, 11 | "author": "", 12 | "license": "ISC", 13 | "dependencies": { 14 | "cors": "^2.8.5", 15 | "dotenv": "^16.4.5", 16 | "express": "^4.19.2", 17 | "express-fileupload": "^1.5.0", 18 | "mongoose": "^8.4.3", 19 | "nodemon": "^3.1.3" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/schema/plp.schema.js: -------------------------------------------------------------------------------- 1 | import { Schema, model, Types } from "mongoose"; 2 | const plpSchema = new Schema( 3 | { 4 | 5 | title: { 6 | type: String, 7 | required: true 8 | }, 9 | imageLink: { 10 | type: String, 11 | required: true, 12 | }, 13 | 14 | }, 15 | { 16 | timestamps: { 17 | createdAt: "create_at", 18 | deletedAt: "delete_at", 19 | }, 20 | } 21 | ); 22 | 23 | export default model("plp", plpSchema); 24 | -------------------------------------------------------------------------------- /src/schema/header.schema.js: -------------------------------------------------------------------------------- 1 | import { Schema, model, Types } from "mongoose"; 2 | const headerSchema = new Schema( 3 | { 4 | 5 | title: { 6 | type: String, 7 | required: true 8 | }, 9 | imageLink: { 10 | type: String, 11 | required: true, 12 | }, 13 | 14 | }, 15 | { 16 | timestamps: { 17 | createdAt: "create_at", 18 | deletedAt: "delete_at", 19 | }, 20 | } 21 | ); 22 | 23 | export default model("headers", headerSchema); 24 | -------------------------------------------------------------------------------- /src/schema/editoril.schema.js: -------------------------------------------------------------------------------- 1 | import { Schema, model, Types } from "mongoose"; 2 | const editorilSchema = new Schema( 3 | { 4 | 5 | 6 | imageLink: { 7 | type: String, 8 | required: true, 9 | }, 10 | description: { 11 | type: String, 12 | required: true, 13 | }, 14 | 15 | }, 16 | { 17 | timestamps: { 18 | createdAt: "create_at", 19 | deletedAt: "delete_at", 20 | }, 21 | } 22 | ); 23 | 24 | export default model("editoril", editorilSchema); 25 | -------------------------------------------------------------------------------- /src/schema/productreco.schema.js: -------------------------------------------------------------------------------- 1 | import { Schema, model, Types } from "mongoose"; 2 | const productFeaturesSchema = new Schema( 3 | { 4 | 5 | title: { 6 | type: String, 7 | required: true 8 | }, 9 | product_ref_id: [{ 10 | type: Types.ObjectId, 11 | ref: "products", 12 | key: "_id", 13 | required: true, 14 | }], 15 | 16 | }, 17 | { 18 | timestamps: { 19 | createdAt: "create_at", 20 | deletedAt: "delete_at", 21 | }, 22 | } 23 | ); 24 | 25 | export default model("product-reco", productFeaturesSchema); 26 | -------------------------------------------------------------------------------- /src/schema/editorial.schema.js: -------------------------------------------------------------------------------- 1 | import { Schema, model, Types } from "mongoose"; 2 | const bgSchema = new Schema( 3 | { 4 | 5 | 6 | imageLink: { 7 | type: String, 8 | required: true, 9 | }, 10 | title: { 11 | type: String, 12 | required: true, 13 | }, 14 | description: { 15 | type: String, 16 | required: true, 17 | }, 18 | 19 | }, 20 | { 21 | timestamps: { 22 | createdAt: "create_at", 23 | deletedAt: "delete_at", 24 | }, 25 | } 26 | ); 27 | 28 | export default model("editorial", bgSchema); 29 | -------------------------------------------------------------------------------- /src/schema/product-feature.schema.js: -------------------------------------------------------------------------------- 1 | import { Schema, model, Types } from "mongoose"; 2 | const productFeaturesSchema = new Schema( 3 | { 4 | 5 | title: { 6 | type: String, 7 | required: true 8 | }, 9 | product_ref_id: [{ 10 | type: Types.ObjectId, 11 | ref: "products", 12 | key: "_id", 13 | required: true, 14 | }], 15 | 16 | }, 17 | { 18 | timestamps: { 19 | createdAt: "create_at", 20 | deletedAt: "delete_at", 21 | }, 22 | } 23 | ); 24 | 25 | export default model("product-features", productFeaturesSchema); 26 | -------------------------------------------------------------------------------- /src/schema/pdp.schema.js: -------------------------------------------------------------------------------- 1 | import { Schema, model, Types } from "mongoose"; 2 | const plpSchema = new Schema( 3 | { 4 | title: { 5 | type: String, 6 | required: true, 7 | }, 8 | description: { 9 | type: String, 10 | required: true, 11 | }, 12 | bg_image: { 13 | type: String, 14 | required: true, 15 | }, 16 | imageLink: { 17 | type: String, 18 | required: true, 19 | }, 20 | signature_image: { 21 | type: String, 22 | required: true, 23 | }, 24 | }, 25 | { 26 | timestamps: { 27 | createdAt: "create_at", 28 | deletedAt: "delete_at", 29 | }, 30 | } 31 | ); 32 | 33 | export default model("pdp", plpSchema); 34 | -------------------------------------------------------------------------------- /src/schema/users.schema.js: -------------------------------------------------------------------------------- 1 | import { Schema, model, Types } from "mongoose"; 2 | const usersSchema = new Schema( 3 | { 4 | 5 | username: { 6 | type: String, 7 | required: true 8 | }, 9 | 10 | email: { 11 | type: String, 12 | required: true 13 | }, 14 | 15 | password: { 16 | type: String, 17 | required: true 18 | }, 19 | 20 | birth_date: { 21 | type: String, 22 | required: true 23 | }, 24 | 25 | }, 26 | { 27 | timestamps: { 28 | createdAt: "create_at", 29 | deletedAt: "delete_at", 30 | }, 31 | } 32 | ); 33 | 34 | export default model("users", usersSchema); 35 | -------------------------------------------------------------------------------- /src/schema/bookmark.schema.js: -------------------------------------------------------------------------------- 1 | 2 | import { Schema, model, Types } from "mongoose"; 3 | const bookSchema = new Schema( 4 | { 5 | 6 | 7 | product_ref_id: { 8 | type: Types.ObjectId, 9 | ref: "products", 10 | key: "_id", 11 | required: true, 12 | }, 13 | user_ref_id: { 14 | type: Types.ObjectId, 15 | ref: "users", 16 | key: "_id", 17 | required: true, 18 | }, 19 | count: { 20 | type: String, 21 | required: true 22 | } 23 | 24 | }, 25 | { 26 | timestamps: { 27 | createdAt: "create_at", 28 | deletedAt: "delete_at", 29 | }, 30 | } 31 | ); 32 | 33 | export default model("bookmark", bookSchema); 34 | -------------------------------------------------------------------------------- /src/model/pdp.model.js: -------------------------------------------------------------------------------- 1 | import headMod from "../schema/pdp.schema.js"; 2 | import { Types } from "mongoose"; 3 | 4 | class Pdp { 5 | async select(id, filter, option) { 6 | try { 7 | if (id) return await headMod.findById(id, option); 8 | return await headMod.find(filter, option); 9 | } catch (error) { 10 | return error.message; 11 | } 12 | } 13 | async insert(body) { 14 | try { 15 | return await headMod.create(body); 16 | } catch (error) { 17 | return error.message; 18 | } 19 | } 20 | async update(id, obj) { 21 | return await headMod.findOneAndUpdate(id, obj); 22 | } 23 | async delete(id) { 24 | return await headMod.deleteOne( 25 | { _id: new Types.ObjectId(id) }, 26 | { close_at: Date.now() }, 27 | { upsert: true } 28 | ); 29 | } 30 | } 31 | 32 | export default new Pdp(); -------------------------------------------------------------------------------- /src/model/plp.modul.js: -------------------------------------------------------------------------------- 1 | import headMod from "../schema/plp.schema.js"; 2 | import { Types } from "mongoose"; 3 | 4 | class Plp { 5 | async select(id, filter, option) { 6 | try { 7 | if (id) return await headMod.findById(id, option); 8 | return await headMod.find(filter, option); 9 | } catch (error) { 10 | return error.message; 11 | } 12 | } 13 | async insert(body) { 14 | try { 15 | return await headMod.create(body); 16 | } catch (error) { 17 | return error.message; 18 | } 19 | } 20 | async update(id, obj) { 21 | return await headMod.findOneAndUpdate(id, obj); 22 | } 23 | async delete(id) { 24 | return await headMod.deleteOne( 25 | { _id: new Types.ObjectId(id) }, 26 | { close_at: Date.now() }, 27 | { upsert: true } 28 | ); 29 | } 30 | } 31 | 32 | export default new Plp(); -------------------------------------------------------------------------------- /src/model/bg.modul.js: -------------------------------------------------------------------------------- 1 | import headMod from "../schema/bgImage.schema.js"; 2 | import { Types } from "mongoose"; 3 | 4 | class bgImage { 5 | async select(id, filter, option) { 6 | try { 7 | if (id) return await headMod.findById(id, option); 8 | return await headMod.find(filter, option); 9 | } catch (error) { 10 | return error.message; 11 | } 12 | } 13 | async insert(body) { 14 | try { 15 | return await headMod.create(body); 16 | } catch (error) { 17 | return error.message; 18 | } 19 | } 20 | async update(id, obj) { 21 | return await headMod.findOneAndUpdate(id, obj); 22 | } 23 | async delete(id) { 24 | return await headMod.deleteOne( 25 | { _id: new Types.ObjectId(id) }, 26 | { close_at: Date.now() }, 27 | { upsert: true } 28 | ); 29 | } 30 | } 31 | 32 | export default new bgImage(); -------------------------------------------------------------------------------- /src/model/header.model.js: -------------------------------------------------------------------------------- 1 | import headMod from "../schema/header.schema.js"; 2 | import { Types } from "mongoose"; 3 | 4 | class Header { 5 | async select(id, filter, option) { 6 | try { 7 | if (id) return await headMod.findById(id, option) 8 | return await headMod.find(filter, option) 9 | } catch (error) { 10 | return error.message; 11 | } 12 | } 13 | async insert(body) { 14 | try { 15 | return await headMod.create(body); 16 | } catch (error) { 17 | return error.message; 18 | } 19 | } 20 | async update(id, obj) { 21 | return await headMod.findOneAndUpdate(id, obj); 22 | } 23 | async delete(id) { 24 | return await headMod.deleteOne( 25 | { _id: new Types.ObjectId(id) }, 26 | { close_at: Date.now() }, 27 | { upsert: true } 28 | ); 29 | } 30 | } 31 | 32 | export default new Header(); -------------------------------------------------------------------------------- /src/model/users.modul.js: -------------------------------------------------------------------------------- 1 | import headMod from "../schema/users.schema.js"; 2 | import { Types } from "mongoose"; 3 | 4 | class Users { 5 | async select(id, filter, option) { 6 | try { 7 | if (id) return await headMod.findById(id, option); 8 | return await headMod.find(filter, option); 9 | } catch (error) { 10 | return error.message; 11 | } 12 | } 13 | async insert(body) { 14 | try { 15 | return await headMod.create(body); 16 | } catch (error) { 17 | return error.message; 18 | } 19 | } 20 | async update(id, obj) { 21 | return await headMod.findOneAndUpdate(id, obj); 22 | } 23 | async delete(id) { 24 | return await headMod.deleteOne( 25 | { _id: new Types.ObjectId(id) }, 26 | { close_at: Date.now() }, 27 | { upsert: true } 28 | ); 29 | } 30 | } 31 | 32 | export default new Users(); -------------------------------------------------------------------------------- /src/model/category.modal.js: -------------------------------------------------------------------------------- 1 | import headMod from "../schema/category.schema.js"; 2 | import { Types } from "mongoose"; 3 | 4 | class categoryM { 5 | async select(id, filter, option) { 6 | try { 7 | if (id) return await headMod.findById(id, option); 8 | return await headMod.find(filter, option); 9 | } catch (error) { 10 | return error.message; 11 | } 12 | } 13 | async insert(body) { 14 | try { 15 | return await headMod.create(body); 16 | } catch (error) { 17 | return error.message; 18 | } 19 | } 20 | async update(id, obj) { 21 | return await headMod.findOneAndUpdate(id, obj); 22 | } 23 | async delete(id) { 24 | return await headMod.deleteOne( 25 | { _id: new Types.ObjectId(id) }, 26 | { close_at: Date.now() }, 27 | { upsert: true } 28 | ); 29 | } 30 | } 31 | 32 | export default new categoryM(); -------------------------------------------------------------------------------- /src/model/editoril.modal.js: -------------------------------------------------------------------------------- 1 | import headMod from "../schema/editoril.schema.js"; 2 | import { Types } from "mongoose"; 3 | 4 | class editorial { 5 | async select(id, filter, option) { 6 | try { 7 | if (id) return await headMod.findById(id, option); 8 | return await headMod.find(filter, option); 9 | } catch (error) { 10 | return error.message; 11 | } 12 | } 13 | async insert(body) { 14 | try { 15 | return await headMod.create(body); 16 | } catch (error) { 17 | return error.message; 18 | } 19 | } 20 | async update(id, obj) { 21 | return await headMod.findOneAndUpdate(id, obj); 22 | } 23 | async delete(id) { 24 | return await headMod.deleteOne( 25 | { _id: new Types.ObjectId(id) }, 26 | { close_at: Date.now() }, 27 | { upsert: true } 28 | ); 29 | } 30 | } 31 | 32 | export default new editorial(); -------------------------------------------------------------------------------- /src/model/editorial.modal.js: -------------------------------------------------------------------------------- 1 | import headMod from "../schema/editorial.schema.js"; 2 | import { Types } from "mongoose"; 3 | 4 | class editorial { 5 | async select(id, filter, option) { 6 | try { 7 | if (id) return await headMod.findById(id, option); 8 | return await headMod.find(filter, option); 9 | } catch (error) { 10 | return error.message; 11 | } 12 | } 13 | async insert(body) { 14 | try { 15 | return await headMod.create(body); 16 | } catch (error) { 17 | return error.message; 18 | } 19 | } 20 | async update(id, obj) { 21 | return await headMod.findOneAndUpdate(id, obj); 22 | } 23 | async delete(id) { 24 | return await headMod.deleteOne( 25 | { _id: new Types.ObjectId(id) }, 26 | { close_at: Date.now() }, 27 | { upsert: true } 28 | ); 29 | } 30 | } 31 | 32 | export default new editorial(); -------------------------------------------------------------------------------- /src/model/products.model.js: -------------------------------------------------------------------------------- 1 | import headMod from "../schema/product.schema.js"; 2 | import { Types } from "mongoose"; 3 | 4 | class Users { 5 | async select(id, filter, option) { 6 | try { 7 | if (id) return await headMod.findById(id, option).populate("cat_ref_id"); 8 | return await headMod.find(filter, option).populate("cat_ref_id");; 9 | } catch (error) { 10 | return error.message; 11 | } 12 | } 13 | async insert(body) { 14 | try { 15 | return await headMod.create(body); 16 | } catch (error) { 17 | return error.message; 18 | } 19 | } 20 | async update(id, obj) { 21 | return await headMod.findOneAndUpdate(id, obj); 22 | } 23 | async delete(id) { 24 | return await headMod.deleteOne( 25 | { _id: new Types.ObjectId(id) }, 26 | { close_at: Date.now() }, 27 | { upsert: true } 28 | ); 29 | } 30 | } 31 | 32 | export default new Users(); -------------------------------------------------------------------------------- /src/model/product.model.js: -------------------------------------------------------------------------------- 1 | import headMod from "../schema/productreco.schema.js"; 2 | import { Types } from "mongoose"; 3 | 4 | class ProductF { 5 | async select(id, filter, option) { 6 | try { 7 | if (id) return await headMod.findById(id, option).populate("product_ref_id"); 8 | return await headMod.find(filter, option).populate("product_ref_id"); 9 | } catch (error) { 10 | return error.message; 11 | } 12 | } 13 | async insert(body) { 14 | try { 15 | return await headMod.create(body); 16 | } catch (error) { 17 | return error.message; 18 | } 19 | } 20 | async update(id, obj) { 21 | return await headMod.findOneAndUpdate(id, obj); 22 | } 23 | async delete(id) { 24 | return await headMod.deleteOne( 25 | { _id: new Types.ObjectId(id) }, 26 | { close_at: Date.now() }, 27 | { upsert: true } 28 | ); 29 | } 30 | } 31 | 32 | export default new ProductF(); -------------------------------------------------------------------------------- /src/model/product-features.model.js: -------------------------------------------------------------------------------- 1 | import headMod from "../schema/product-feature.schema.js"; 2 | import { Types } from "mongoose"; 3 | 4 | class ProductF { 5 | async select(id, filter, option) { 6 | try { 7 | if (id) return await headMod.findById(id, option).populate("product_ref_id"); 8 | return await headMod.find(filter, option).populate("product_ref_id"); 9 | } catch (error) { 10 | return error.message; 11 | } 12 | } 13 | async insert(body) { 14 | try { 15 | return await headMod.create(body); 16 | } catch (error) { 17 | return error.message; 18 | } 19 | } 20 | async update(id, obj) { 21 | return await headMod.findOneAndUpdate(id, obj); 22 | } 23 | async delete(id) { 24 | return await headMod.deleteOne( 25 | { _id: new Types.ObjectId(id) }, 26 | { close_at: Date.now() }, 27 | { upsert: true } 28 | ); 29 | } 30 | } 31 | 32 | export default new ProductF(); -------------------------------------------------------------------------------- /src/model/bookmark.model.js: -------------------------------------------------------------------------------- 1 | import headMod from "../schema/bookmark.schema.js"; 2 | import { Types } from "mongoose"; 3 | 4 | class bookmarkM { 5 | async select(id, filter, option) { 6 | try { 7 | if (id) return await headMod.findById(id, option).populate("user_ref_id").populate("product_ref_id"); 8 | return await headMod.find(filter, option).populate("user_ref_id").populate("product_ref_id"); 9 | } catch (error) { 10 | return error.message; 11 | } 12 | } 13 | async insert(body) { 14 | try { 15 | return await headMod.create(body); 16 | } catch (error) { 17 | return error.message; 18 | } 19 | } 20 | async update(id, obj) { 21 | return await headMod.findOneAndUpdate(id, obj); 22 | } 23 | async delete(id) { 24 | return await headMod.deleteOne( 25 | { _id: new Types.ObjectId(id) }, 26 | { close_at: Date.now() }, 27 | { upsert: true } 28 | ); 29 | } 30 | } 31 | 32 | export default new bookmarkM(); -------------------------------------------------------------------------------- /src/schema/product.schema.js: -------------------------------------------------------------------------------- 1 | 2 | import { Schema, model, Types } from "mongoose"; 3 | const productSchema = new Schema( 4 | { 5 | 6 | name: { 7 | type: String, 8 | required: true 9 | }, 10 | 11 | count: { 12 | type: String, 13 | required: true 14 | }, 15 | 16 | imageLink: { 17 | type: String, 18 | required: true 19 | }, 20 | 21 | price: { 22 | type: String, 23 | required: true 24 | }, 25 | sizes: [{ 26 | type: String, 27 | required: true 28 | }], 29 | description: { 30 | type: String, 31 | required: true 32 | }, 33 | details: { 34 | type: String, 35 | required: true 36 | }, 37 | shipping: { 38 | type: String, 39 | required: true 40 | }, 41 | cat_ref_id: [{ 42 | type: Types.ObjectId, 43 | ref: "category", 44 | key: "_id", 45 | required: true, 46 | }], 47 | 48 | }, 49 | { 50 | timestamps: { 51 | createdAt: "create_at", 52 | deletedAt: "delete_at", 53 | }, 54 | } 55 | ); 56 | 57 | export default model("products", productSchema); 58 | -------------------------------------------------------------------------------- /src/server.js: -------------------------------------------------------------------------------- 1 | import express from "express"; 2 | import cors from "cors"; 3 | import "./db/mongodb.js"; 4 | 5 | import headerRouter from "./router/header.router.js"; 6 | import productRouter from "./router/productF.router.js"; 7 | import bgRouter from "./router/bg.router.js"; 8 | import editRouter from "./router/editorial.router.js"; 9 | import editorilRouter from "./router/editoril.router.js"; 10 | import productrecoRouter from "./router/productreco.router.js"; 11 | import catRouter from "./router/category.router.js"; 12 | import userRouter from "./router/users.router.js"; 13 | import bookMRouter from "./router/bookmark.router.js"; 14 | import productsRouter from "./router/product.router.js"; 15 | import plpRouter from "./router/plp.router.js"; 16 | import pdpRouter from "./router/pdp.router.js"; 17 | 18 | const PORT = process.env.PORT || 3000; 19 | const app = express(); 20 | app.use(cors()); 21 | app.use(express.json()); 22 | 23 | app.use("/headers", headerRouter); 24 | app.use("/product-features", productRouter); 25 | app.use("/bgImage", bgRouter); 26 | app.use("/editorial", editRouter); 27 | app.use("/editoril", editorilRouter); 28 | app.use("/product-reco", productrecoRouter); 29 | app.use("/category", catRouter); 30 | app.use("/users", userRouter); 31 | app.use("/bookmark", bookMRouter); 32 | app.use("/products", productsRouter); 33 | app.use("/plp", plpRouter); 34 | app.use("/pdp", pdpRouter); 35 | 36 | app.listen(PORT); 37 | console.log("server listening " + PORT); 38 | -------------------------------------------------------------------------------- /src/controller/plp.contr.js: -------------------------------------------------------------------------------- 1 | import header from "../model/plp.modul.js"; 2 | 3 | class plpContr { 4 | async get(req, res) { 5 | try { 6 | const id = req.params?.id; 7 | let data; 8 | if (id) data = await header.select(id); 9 | else if (Object.keys(req.query).length) 10 | data = await header.select(null, req.query); 11 | else data = await header.select(); 12 | return res.send({ 13 | status: 200, 14 | data, 15 | message: "PLP", 16 | }); 17 | } catch (error) { 18 | return res.status(404).json({ 19 | status: 404, 20 | data: null, 21 | message: error.message, 22 | }); 23 | } 24 | } 25 | async post(req, res) { 26 | try { 27 | let { title, imageLink } = req.body; 28 | 29 | res.send({ 30 | status: 201, 31 | data: await header.insert({ 32 | title: title, 33 | imageLink: imageLink, 34 | }), 35 | message: "success", 36 | }); 37 | } catch (error) { 38 | return res.status(400).json({ 39 | status: 400, 40 | data: null, 41 | message: error.message, 42 | }); 43 | } 44 | } 45 | 46 | async put(req, res) { 47 | try { 48 | const id = req.params?.id; 49 | let data; 50 | 51 | let { title, imageLink } = req.body; 52 | 53 | const obj = { 54 | $set: { 55 | title: title ? title : data.title, 56 | imageLink: imageLink ? imageLink : data.imageLink, 57 | }, 58 | }; 59 | return res.send({ 60 | status: 201, 61 | data: await header.update({ _id: id }, obj), 62 | }); 63 | } catch (error) { 64 | return res.status(404).json({ 65 | status: 404, 66 | data: null, 67 | message: error.message, 68 | }); 69 | } 70 | } 71 | async delete(req, res) { 72 | try { 73 | const id = req.params?.id; 74 | 75 | return res.send({ 76 | status: 201, 77 | data: await header.delete(id), 78 | message: "success", 79 | }); 80 | } catch (error) { 81 | return res.status(404).json({ 82 | status: 404, 83 | data: null, 84 | message: error.message, 85 | }); 86 | } 87 | } 88 | } 89 | 90 | export default new plpContr(); 91 | -------------------------------------------------------------------------------- /src/controller/bg.contr.js: -------------------------------------------------------------------------------- 1 | import header from "../model/bg.modul.js"; 2 | 3 | class headerContr { 4 | async get(req, res) { 5 | try { 6 | const id = req.params?.id; 7 | let data; 8 | if (id) data = await header.select(id); 9 | else if (Object.keys(req.query).length) 10 | data = await header.select(null, req.query); 11 | else data = await header.select(); 12 | return res.send({ 13 | status: 200, 14 | data, 15 | message: "bg-Image", 16 | }); 17 | } catch (error) { 18 | return res.status(404).json({ 19 | status: 404, 20 | data: null, 21 | message: error.message, 22 | }); 23 | } 24 | } 25 | async post(req, res) { 26 | try { 27 | let { imageLink } = req.body; 28 | 29 | res.send({ 30 | status: 201, 31 | data: await header.insert({ 32 | 33 | imageLink: imageLink 34 | }), 35 | message: "success", 36 | }); 37 | 38 | } catch (error) { 39 | return res.status(400).json({ 40 | status: 400, 41 | data: null, 42 | message: error.message, 43 | }); 44 | } 45 | } 46 | 47 | async put(req, res) { 48 | try { 49 | const id = req.params?.id; 50 | let data; 51 | 52 | let { title, imageLink } = req.body; 53 | 54 | const obj = { 55 | $set: { 56 | 57 | imageLink: imageLink ? imageLink : data.imageLink, 58 | }, 59 | }; 60 | return res.send({ 61 | status: 201, 62 | data: await header.update({ _id: id }, obj), 63 | }); 64 | 65 | 66 | } catch (error) { 67 | return res.status(404).json({ 68 | status: 404, 69 | data: null, 70 | message: error.message, 71 | }); 72 | } 73 | } 74 | async delete(req, res) { 75 | try { 76 | const id = req.params?.id; 77 | 78 | return res.send({ 79 | status: 201, 80 | data: await header.delete(id), 81 | message: "success", 82 | }); 83 | } catch (error) { 84 | return res.status(404).json({ 85 | status: 404, 86 | data: null, 87 | message: error.message, 88 | }); 89 | } 90 | } 91 | } 92 | 93 | export default new headerContr(); 94 | -------------------------------------------------------------------------------- /src/controller/category.contr.js: -------------------------------------------------------------------------------- 1 | import header from "../model/category.modal.js"; 2 | 3 | class categoryContr { 4 | 5 | async get(req, res) { 6 | try { 7 | const id = req.params?.id; 8 | let data; 9 | if (id) data = await header.select(id); 10 | else if (Object.keys(req.query).length) 11 | data = await header.select(null, req.query); 12 | else data = await header.select(); 13 | return res.send({ 14 | status: 200, 15 | data, 16 | message: "category", 17 | }); 18 | } catch (error) { 19 | return res.status(404).json({ 20 | status: 404, 21 | data: null, 22 | message: error.message, 23 | }); 24 | } 25 | } 26 | 27 | async post(req, res) { 28 | try { 29 | let { cat_name } = req.body; 30 | 31 | res.send({ 32 | status: 201, 33 | data: await header.insert({ 34 | 35 | cat_name: cat_name 36 | }), 37 | message: "success", 38 | }); 39 | 40 | } catch (error) { 41 | return res.status(400).json({ 42 | status: 400, 43 | data: null, 44 | message: error.message, 45 | }); 46 | } 47 | } 48 | 49 | async put(req, res) { 50 | try { 51 | const id = req.params?.id; 52 | let data; 53 | 54 | let { cat_name } = req.body; 55 | 56 | const obj = { 57 | $set: { 58 | 59 | cat_name: cat_name ? cat_name : data.cat_name, 60 | }, 61 | }; 62 | return res.send({ 63 | status: 201, 64 | data: await header.update({ _id: id }, obj), 65 | }); 66 | 67 | 68 | } catch (error) { 69 | return res.status(404).json({ 70 | status: 404, 71 | data: null, 72 | message: error.message, 73 | }); 74 | } 75 | } 76 | 77 | async delete(req, res) { 78 | try { 79 | const id = req.params?.id; 80 | 81 | return res.send({ 82 | status: 201, 83 | data: await header.delete(id), 84 | message: "success", 85 | }); 86 | } catch (error) { 87 | return res.status(404).json({ 88 | status: 404, 89 | data: null, 90 | message: error.message, 91 | }); 92 | } 93 | } 94 | 95 | } 96 | 97 | export default new categoryContr(); 98 | -------------------------------------------------------------------------------- /src/controller/header.contr.js: -------------------------------------------------------------------------------- 1 | import header from "../model/header.model.js"; 2 | 3 | class headerContr { 4 | async get(req, res) { 5 | try { 6 | const id = req.params?.id; 7 | let data; 8 | if (id) data = await header.select(id); 9 | else if (Object.keys(req.query).length) 10 | data = await header.select(null, req.query); 11 | else data = await header.select(); 12 | return res.send({ 13 | status: 200, 14 | data, 15 | message: "headers", 16 | }); 17 | } catch (error) { 18 | return res.status(404).json({ 19 | status: 404, 20 | data: null, 21 | message: error.message, 22 | }); 23 | } 24 | } 25 | async post(req, res) { 26 | try { 27 | let { title, imageLink } = req.body; 28 | 29 | res.send({ 30 | status: 201, 31 | data: await header.insert({ 32 | title: title, 33 | imageLink: imageLink 34 | }), 35 | message: "success", 36 | }); 37 | 38 | } catch (error) { 39 | return res.status(400).json({ 40 | status: 400, 41 | data: null, 42 | message: error.message, 43 | }); 44 | } 45 | } 46 | 47 | async put(req, res) { 48 | try { 49 | const id = req.params?.id; 50 | let data; 51 | 52 | let { title, imageLink } = req.body; 53 | 54 | const obj = { 55 | $set: { 56 | title: title ? title : data.title, 57 | imageLink: imageLink ? imageLink : data.imageLink, 58 | }, 59 | }; 60 | return res.send({ 61 | status: 201, 62 | data: await header.update({ _id: id }, obj), 63 | }); 64 | 65 | 66 | } catch (error) { 67 | return res.status(404).json({ 68 | status: 404, 69 | data: null, 70 | message: error.message, 71 | }); 72 | } 73 | } 74 | async delete(req, res) { 75 | try { 76 | const id = req.params?.id; 77 | 78 | return res.send({ 79 | status: 201, 80 | data: await header.delete(id), 81 | message: "success", 82 | }); 83 | } catch (error) { 84 | return res.status(404).json({ 85 | status: 404, 86 | data: null, 87 | message: error.message, 88 | }); 89 | } 90 | } 91 | } 92 | 93 | export default new headerContr(); 94 | -------------------------------------------------------------------------------- /src/controller/productreco.contr.js: -------------------------------------------------------------------------------- 1 | import header from "../model/product.model.js"; 2 | 3 | class productFContr { 4 | async get(req, res) { 5 | try { 6 | const id = req.params?.id; 7 | let data; 8 | if (id) data = await header.select(id); 9 | else if (Object.keys(req.query).length) 10 | data = await header.select(null, req.query); 11 | else data = await header.select(); 12 | return res.send({ 13 | status: 200, 14 | data, 15 | message: "product-reco", 16 | }); 17 | } catch (error) { 18 | return res.status(404).json({ 19 | status: 404, 20 | data: null, 21 | message: error.message, 22 | }); 23 | } 24 | } 25 | async post(req, res) { 26 | try { 27 | let { title, product_ref_id } = req.body; 28 | 29 | res.send({ 30 | status: 201, 31 | data: await header.insert({ 32 | title: title, 33 | product_ref_id: product_ref_id 34 | }), 35 | message: "success", 36 | }); 37 | 38 | } catch (error) { 39 | return res.status(400).json({ 40 | status: 400, 41 | data: null, 42 | message: error.message, 43 | }); 44 | } 45 | } 46 | 47 | async put(req, res) { 48 | try { 49 | const id = req.params?.id; 50 | let data; 51 | 52 | let { title, product_ref_id } = req.body; 53 | 54 | const obj = { 55 | $set: { 56 | title: title ? title : data.title, 57 | product_ref_id: product_ref_id ? product_ref_id : data.product_ref_id, 58 | }, 59 | }; 60 | return res.send({ 61 | status: 201, 62 | data: await header.update({ _id: id }, obj), 63 | }); 64 | 65 | } catch (error) { 66 | return res.status(404).json({ 67 | status: 404, 68 | data: null, 69 | message: error.message, 70 | }); 71 | } 72 | } 73 | async delete(req, res) { 74 | try { 75 | const id = req.params?.id; 76 | 77 | return res.send({ 78 | status: 201, 79 | data: await header.delete(id), 80 | message: "success", 81 | }); 82 | } catch (error) { 83 | return res.status(404).json({ 84 | status: 404, 85 | data: null, 86 | message: error.message, 87 | }); 88 | } 89 | } 90 | } 91 | 92 | export default new productFContr(); 93 | -------------------------------------------------------------------------------- /src/controller/productF.contr.js: -------------------------------------------------------------------------------- 1 | import header from "../model/product-features.model.js"; 2 | 3 | class productFContr { 4 | async get(req, res) { 5 | try { 6 | const id = req.params?.id; 7 | let data; 8 | if (id) data = await header.select(id); 9 | else if (Object.keys(req.query).length) 10 | data = await header.select(null, req.query); 11 | else data = await header.select(); 12 | return res.send({ 13 | status: 200, 14 | data, 15 | message: "product-features", 16 | }); 17 | } catch (error) { 18 | return res.status(404).json({ 19 | status: 404, 20 | data: null, 21 | message: error.message, 22 | }); 23 | } 24 | } 25 | async post(req, res) { 26 | try { 27 | let { title, product_ref_id } = req.body; 28 | 29 | res.send({ 30 | status: 201, 31 | data: await header.insert({ 32 | title: title, 33 | product_ref_id: product_ref_id 34 | }), 35 | message: "success", 36 | }); 37 | 38 | } catch (error) { 39 | return res.status(400).json({ 40 | status: 400, 41 | data: null, 42 | message: error.message, 43 | }); 44 | } 45 | } 46 | 47 | async put(req, res) { 48 | try { 49 | const id = req.params?.id; 50 | let data; 51 | 52 | let { title, product_ref_id } = req.body; 53 | 54 | const obj = { 55 | $set: { 56 | title: title ? title : data.title, 57 | product_ref_id: product_ref_id ? product_ref_id : data.product_ref_id, 58 | }, 59 | }; 60 | return res.send({ 61 | status: 201, 62 | data: await header.update({ _id: id }, obj), 63 | }); 64 | 65 | } catch (error) { 66 | return res.status(404).json({ 67 | status: 404, 68 | data: null, 69 | message: error.message, 70 | }); 71 | } 72 | } 73 | async delete(req, res) { 74 | try { 75 | const id = req.params?.id; 76 | 77 | return res.send({ 78 | status: 201, 79 | data: await header.delete(id), 80 | message: "success", 81 | }); 82 | } catch (error) { 83 | return res.status(404).json({ 84 | status: 404, 85 | data: null, 86 | message: error.message, 87 | }); 88 | } 89 | } 90 | } 91 | 92 | export default new productFContr(); 93 | -------------------------------------------------------------------------------- /src/controller/editoril.contr.js: -------------------------------------------------------------------------------- 1 | import header from "../model/editoril.modal.js"; 2 | 3 | class editorailContr { 4 | async get(req, res) { 5 | try { 6 | const id = req.params?.id; 7 | let data; 8 | if (id) data = await header.select(id); 9 | else if (Object.keys(req.query).length) 10 | data = await header.select(null, req.query); 11 | else data = await header.select(); 12 | return res.send({ 13 | status: 200, 14 | data, 15 | message: "editoril-CTA", 16 | }); 17 | } catch (error) { 18 | return res.status(404).json({ 19 | status: 404, 20 | data: null, 21 | message: error.message, 22 | }); 23 | } 24 | } 25 | async post(req, res) { 26 | try { 27 | let { imageLink, description } = req.body; 28 | 29 | res.send({ 30 | status: 201, 31 | data: await header.insert({ 32 | 33 | imageLink: imageLink, 34 | description: description 35 | }), 36 | message: "success", 37 | }); 38 | 39 | } catch (error) { 40 | return res.status(400).json({ 41 | status: 400, 42 | data: null, 43 | message: error.message, 44 | }); 45 | } 46 | } 47 | 48 | async put(req, res) { 49 | try { 50 | const id = req.params?.id; 51 | let data; 52 | 53 | let { imageLink, description } = req.body; 54 | 55 | const obj = { 56 | $set: { 57 | imageLink: imageLink ? imageLink : data.imageLink, 58 | description: description ? description : data.description, 59 | }, 60 | }; 61 | return res.send({ 62 | status: 201, 63 | data: await header.update({ _id: id }, obj), 64 | }); 65 | 66 | 67 | } catch (error) { 68 | return res.status(404).json({ 69 | status: 404, 70 | data: null, 71 | message: error.message, 72 | }); 73 | } 74 | } 75 | async delete(req, res) { 76 | try { 77 | const id = req.params?.id; 78 | 79 | return res.send({ 80 | status: 201, 81 | data: await header.delete(id), 82 | message: "success", 83 | }); 84 | } catch (error) { 85 | return res.status(404).json({ 86 | status: 404, 87 | data: null, 88 | message: error.message, 89 | }); 90 | } 91 | } 92 | } 93 | 94 | export default new editorailContr(); 95 | -------------------------------------------------------------------------------- /src/controller/pdp.contr.js: -------------------------------------------------------------------------------- 1 | import header from "../model/pdp.model.js"; 2 | 3 | class pdpContr { 4 | async get(req, res) { 5 | try { 6 | const id = req.params?.id; 7 | let data; 8 | if (id) data = await header.select(id); 9 | else if (Object.keys(req.query).length) 10 | data = await header.select(null, req.query); 11 | else data = await header.select(); 12 | return res.send({ 13 | status: 200, 14 | data, 15 | message: "PDP", 16 | }); 17 | } catch (error) { 18 | return res.status(404).json({ 19 | status: 404, 20 | data: null, 21 | message: error.message, 22 | }); 23 | } 24 | } 25 | async post(req, res) { 26 | try { 27 | let { title, imageLink, description, bg_image, signature_image } = 28 | req.body; 29 | 30 | res.send({ 31 | status: 201, 32 | data: await header.insert({ 33 | title: title, 34 | description: description, 35 | bg_image: bg_image, 36 | signature_image: signature_image, 37 | imageLink: imageLink, 38 | }), 39 | message: "success", 40 | }); 41 | } catch (error) { 42 | return res.status(400).json({ 43 | status: 400, 44 | data: null, 45 | message: error.message, 46 | }); 47 | } 48 | } 49 | 50 | async put(req, res) { 51 | try { 52 | const id = req.params?.id; 53 | let data; 54 | 55 | let { title, imageLink, description, bg_image, signature_image } = 56 | req.body; 57 | 58 | const obj = { 59 | $set: { 60 | title: title ? title : data.title, 61 | description: description ? description : data.description, 62 | signature_image: signature_image 63 | ? signature_image 64 | : data.signature_image, 65 | bg_image: bg_image ? bg_image : data.bg_image, 66 | imageLink: imageLink ? imageLink : data.imageLink, 67 | }, 68 | }; 69 | return res.send({ 70 | status: 201, 71 | data: await header.update({ _id: id }, obj), 72 | }); 73 | } catch (error) { 74 | return res.status(404).json({ 75 | status: 404, 76 | data: null, 77 | message: error.message, 78 | }); 79 | } 80 | } 81 | async delete(req, res) { 82 | try { 83 | const id = req.params?.id; 84 | 85 | return res.send({ 86 | status: 201, 87 | data: await header.delete(id), 88 | message: "success", 89 | }); 90 | } catch (error) { 91 | return res.status(404).json({ 92 | status: 404, 93 | data: null, 94 | message: error.message, 95 | }); 96 | } 97 | } 98 | } 99 | 100 | export default new pdpContr(); 101 | -------------------------------------------------------------------------------- /src/controller/editorial.contr.js: -------------------------------------------------------------------------------- 1 | import header from "../model/editorial.modal.js"; 2 | 3 | class editorailContr { 4 | async get(req, res) { 5 | try { 6 | const id = req.params?.id; 7 | let data; 8 | if (id) data = await header.select(id); 9 | else if (Object.keys(req.query).length) 10 | data = await header.select(null, req.query); 11 | else data = await header.select(); 12 | return res.send({ 13 | status: 200, 14 | data, 15 | message: "editorial", 16 | }); 17 | } catch (error) { 18 | return res.status(404).json({ 19 | status: 404, 20 | data: null, 21 | message: error.message, 22 | }); 23 | } 24 | } 25 | async post(req, res) { 26 | try { 27 | let { title, imageLink, description } = req.body; 28 | 29 | res.send({ 30 | status: 201, 31 | data: await header.insert({ 32 | title: title, 33 | imageLink: imageLink, 34 | description: description 35 | }), 36 | message: "success", 37 | }); 38 | 39 | } catch (error) { 40 | return res.status(400).json({ 41 | status: 400, 42 | data: null, 43 | message: error.message, 44 | }); 45 | } 46 | } 47 | 48 | async put(req, res) { 49 | try { 50 | const id = req.params?.id; 51 | let data; 52 | 53 | let { title, imageLink, description } = req.body; 54 | 55 | const obj = { 56 | $set: { 57 | title: title ? title : data.title, 58 | imageLink: imageLink ? imageLink : data.imageLink, 59 | description: description ? description : data.description, 60 | }, 61 | }; 62 | return res.send({ 63 | status: 201, 64 | data: await header.update({ _id: id }, obj), 65 | }); 66 | 67 | 68 | } catch (error) { 69 | return res.status(404).json({ 70 | status: 404, 71 | data: null, 72 | message: error.message, 73 | }); 74 | } 75 | } 76 | async delete(req, res) { 77 | try { 78 | const id = req.params?.id; 79 | 80 | return res.send({ 81 | status: 201, 82 | data: await header.delete(id), 83 | message: "success", 84 | }); 85 | } catch (error) { 86 | return res.status(404).json({ 87 | status: 404, 88 | data: null, 89 | message: error.message, 90 | }); 91 | } 92 | } 93 | } 94 | 95 | export default new editorailContr(); 96 | -------------------------------------------------------------------------------- /src/controller/users.contr.js: -------------------------------------------------------------------------------- 1 | import header from "../model/users.modul.js"; 2 | import dotenv from "dotenv"; 3 | dotenv.config(); 4 | 5 | class usersContr { 6 | async get(req, res) { 7 | try { 8 | const id = req.params?.id; 9 | let data; 10 | if (id) data = await header.select(id); 11 | else if (Object.keys(req.query).length) 12 | data = await header.select(null, req.query); 13 | else data = await header.select(); 14 | return res.send({ 15 | status: 200, 16 | data, 17 | message: "users", 18 | }); 19 | } catch (error) { 20 | return res.status(404).json({ 21 | status: 404, 22 | data: null, 23 | message: error.message, 24 | }); 25 | } 26 | } 27 | async login(req, res) { 28 | try { 29 | let admin = { 30 | email: "mrNobody.yahoo.com", 31 | password: "1234", 32 | username: "Tillie Phillips", 33 | birth_date: "2000-03-15", 34 | }; 35 | 36 | let { email, password } = req.body; 37 | let data = await header.select(null, { 38 | email, 39 | password, 40 | }); 41 | 42 | if (data.length > 0) { 43 | const obj = data[0]; 44 | return res.send({ 45 | data: obj, 46 | message: "success", 47 | status: 200, 48 | }); 49 | } else if (admin.email == email && admin.password == password) { 50 | return res.send({ 51 | data: admin, 52 | message: "success", 53 | status: 200, 54 | }); 55 | } 56 | res.send({ status: 404, message: "Ro'yxatdan o'tmagansiz" }); 57 | } catch (error) { 58 | res.send({ status: 404, message: error.message }); 59 | } 60 | } 61 | async register(req, res) { 62 | try { 63 | let { username, email, password, birth_date } = req.body; 64 | 65 | res.send({ 66 | status: 201, 67 | data: await header.insert({ 68 | username: username, 69 | email: email, 70 | password: password, 71 | birth_date: birth_date, 72 | }), 73 | message: "success", 74 | }); 75 | } catch (error) { 76 | return res.status(400).json({ 77 | status: 400, 78 | data: null, 79 | message: error.message, 80 | }); 81 | } 82 | } 83 | 84 | async put(req, res) { 85 | try { 86 | const id = req.params?.id; 87 | let data; 88 | 89 | let { username, email, password, birth_date } = req.body; 90 | 91 | const obj = { 92 | $set: { 93 | username: username ? username : data.username, 94 | email: email ? email : data.email, 95 | password: password ? password : data.password, 96 | birth_date: birth_date ? birth_date : data.birth_date, 97 | }, 98 | }; 99 | return res.send({ 100 | status: 201, 101 | data: await header.update({ _id: id }, obj), 102 | }); 103 | } catch (error) { 104 | return res.status(404).json({ 105 | status: 404, 106 | data: null, 107 | message: error.message, 108 | }); 109 | } 110 | } 111 | async delete(req, res) { 112 | try { 113 | const id = req.params?.id; 114 | 115 | return res.send({ 116 | status: 201, 117 | data: await header.delete(id), 118 | message: "success", 119 | }); 120 | } catch (error) { 121 | return res.status(404).json({ 122 | status: 404, 123 | data: null, 124 | message: error.message, 125 | }); 126 | } 127 | } 128 | } 129 | 130 | export default new usersContr(); 131 | -------------------------------------------------------------------------------- /src/controller/product.contr.js: -------------------------------------------------------------------------------- 1 | import header from "../model/products.model.js"; 2 | 3 | class productsContr { 4 | async get(req, res) { 5 | try { 6 | const id = req.params?.id; 7 | let data; 8 | if (id) data = await header.select(id); 9 | else if (Object.keys(req.query).length) 10 | data = await header.select(null, req.query); 11 | else data = await header.select(); 12 | return res.send({ 13 | status: 200, 14 | data, 15 | message: "products", 16 | }); 17 | } catch (error) { 18 | return res.status(404).json({ 19 | status: 404, 20 | data: null, 21 | message: error.message, 22 | }); 23 | } 24 | } 25 | async post(req, res) { 26 | try { 27 | let { name, count, imageLink, price, size, description, details, shipping, cat_ref_id } = req.body; 28 | 29 | res.send({ 30 | status: 201, 31 | data: await header.insert({ 32 | name: name, 33 | count: count, 34 | imageLink: imageLink, 35 | price: price, 36 | size: size, 37 | description: description, 38 | details: details, 39 | shipping: shipping, 40 | cat_ref_id: cat_ref_id, 41 | }), 42 | message: "success", 43 | }); 44 | 45 | } catch (error) { 46 | return res.status(400).json({ 47 | status: 400, 48 | data: null, 49 | message: error.message, 50 | }); 51 | } 52 | } 53 | 54 | async put(req, res) { 55 | try { 56 | const id = req.params?.id; 57 | let data; 58 | let { name, count, imageLink, price, size, description, details, shipping, cat_ref_id } = req.body; 59 | const obj = { 60 | $set: { 61 | name: name ? name : data.name, 62 | count: count ? count : data.count, 63 | imageLink: imageLink ? imageLink : data.imageLink, 64 | price: price ? price : data.price, 65 | size: size ? size : data.size, 66 | description: description ? description : data.description, 67 | details: details ? details : data.details, 68 | shipping: shipping ? shipping : data.shipping, 69 | cat_ref_id: cat_ref_id ? cat_ref_id : data.cat_ref_id, 70 | }, 71 | }; 72 | return res.send({ 73 | status: 201, 74 | data: await header.update({ _id: id }, obj), 75 | }); 76 | 77 | } catch (error) { 78 | return res.status(404).json({ 79 | status: 404, 80 | data: null, 81 | message: error.message, 82 | }); 83 | } 84 | } 85 | async delete(req, res) { 86 | try { 87 | const id = req.params?.id; 88 | 89 | return res.send({ 90 | status: 201, 91 | data: await header.delete(id), 92 | message: "success", 93 | }); 94 | } catch (error) { 95 | return res.status(404).json({ 96 | status: 404, 97 | data: null, 98 | message: error.message, 99 | }); 100 | } 101 | } 102 | } 103 | 104 | export default new productsContr(); 105 | -------------------------------------------------------------------------------- /src/controller/bookmarl.contr.js: -------------------------------------------------------------------------------- 1 | import header from "../model/bookmark.model.js"; 2 | import users from "../model/users.modul.js"; 3 | import product from "../model/products.model.js"; 4 | class bookMContr { 5 | async get(req, res) { 6 | try { 7 | const id = req.params?.id; 8 | let data; 9 | if (id) data = await header.select(id); 10 | else if (Object.keys(req.query).length) 11 | data = await header.select(null, req.query); 12 | else data = await header.select(); 13 | return res.send({ 14 | status: 200, 15 | data, 16 | message: "bookmark", 17 | }); 18 | } catch (error) { 19 | return res.status(404).json({ 20 | status: 404, 21 | data: null, 22 | message: error.message, 23 | }); 24 | } 25 | } 26 | 27 | async buy(req, res) { 28 | try { 29 | const user_ref_id = req.params?.id; 30 | let user = await header.select(null, { 31 | user_ref_id, 32 | }); 33 | 34 | if (user) { 35 | let zkzId = []; 36 | let proCt = []; 37 | let proId = []; 38 | user.forEach((eid) => { 39 | zkzId.push(eid.id); 40 | proCt.push(eid.count); 41 | proId.push(eid.product_ref_id.id); 42 | }); 43 | 44 | // edit 45 | 46 | for (let i = 0; i < proId.length; i++) { 47 | let pro = await product.select(proId[i]); 48 | let ct = proCt[i]; 49 | 50 | const obj = { 51 | $set: { 52 | user_ref_id: pro.user_ref_id, 53 | product_ref_id: pro.product_ref_id, 54 | count: pro.count ? (pro.count -= ct) : pro.count, 55 | }, 56 | }; 57 | 58 | await product.update({ _id: proId[i] }, obj); 59 | } 60 | // edit end 61 | // del 62 | 63 | zkzId.forEach(async (zkId) => { 64 | await header.delete(zkId); 65 | }); 66 | 67 | return res.send({ 68 | status: 200, 69 | data: "SOTILDI", 70 | message: "success", 71 | }); 72 | } 73 | res.status(404).json({ 74 | status: 404, 75 | data: null, 76 | message: error.message, 77 | }); 78 | } catch (error) { 79 | return res.status(404).json({ 80 | status: 404, 81 | data: null, 82 | message: error.message, 83 | }); 84 | } 85 | } 86 | async post(req, res) { 87 | try { 88 | let { user_ref_id, product_ref_id, count } = req.body; 89 | res.send({ 90 | status: 201, 91 | data: await header.insert({ 92 | user_ref_id: user_ref_id, 93 | product_ref_id: product_ref_id, 94 | count: count, 95 | }), 96 | message: "success", 97 | }); 98 | } catch (error) { 99 | return res.status(400).json({ 100 | status: 400, 101 | data: null, 102 | message: error.message, 103 | }); 104 | } 105 | } 106 | 107 | async put(req, res) { 108 | try { 109 | const id = req.params?.id; 110 | let data; 111 | 112 | let { product_ref_id, user_ref_id, count } = req.body; 113 | 114 | const obj = { 115 | $set: { 116 | user_ref_id: user_ref_id ? user_ref_id : data.user_ref_id, 117 | product_ref_id: product_ref_id ? product_ref_id : data.product_ref_id, 118 | count: count ? count : data.count, 119 | }, 120 | }; 121 | return res.send({ 122 | status: 201, 123 | data: await header.update({ _id: id }, obj), 124 | }); 125 | } catch (error) { 126 | return res.status(404).json({ 127 | status: 404, 128 | data: null, 129 | message: error.message, 130 | }); 131 | } 132 | } 133 | async delete(req, res) { 134 | try { 135 | const id = req.params?.id; 136 | 137 | return res.send({ 138 | status: 201, 139 | data: await header.delete(id), 140 | message: "success", 141 | }); 142 | } catch (error) { 143 | return res.status(404).json({ 144 | status: 404, 145 | data: null, 146 | message: error.message, 147 | }); 148 | } 149 | } 150 | } 151 | 152 | export default new bookMContr(); 153 | --------------------------------------------------------------------------------