Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. [
  2. {
  3. "_id": "5cbabbd7545ac20f7c912e6a",
  4. "refno1": "REF1",
  5. "refno2": "REF2",
  6. "prodregdate": "2019-04-09T00:00:00.000Z",
  7. "data": [
  8. {
  9. "_id": "5cbabbd7545ac20f7c912e6b",
  10. "product": "5cb86b45cfafaa1860e29b2a",
  11. "serialno": "s123"
  12. },
  13. { // this data im not able to enter how to do it
  14. "_id": "5cbabbd7545ac20f7c912e6b",
  15. "product": "5cb86b45cfafaa1860e29b2a",
  16. "serialno": "s123"
  17. },
  18. ],
  19. "customer": {
  20. "_id": "5c98bb0a42207b16d8fbd3cf",
  21. "customername": "Raghav Update"
  22. },
  23. "customertype": {
  24. "_id": "5c7a1a1d4913fa08ac75c027",
  25. "customertype": "Government "
  26. },
  27. "__v": 0
  28. }
  29. ]
  30.  
  31. const mongoose = require('mongoose');
  32. const Schema = mongoose.Schema;
  33.  
  34. const ProductRegistrationSchema = new Schema({
  35. //Product Details
  36. _id: { type: mongoose.Schema.Types.ObjectId },
  37. refno1: { type: String },
  38. refno2: { type: String },
  39. data: [{
  40. product: {
  41. type: mongoose.Schema.Types.ObjectId,
  42. ref: "product"
  43. },
  44. //DATES
  45. //OEM
  46. oemwarrantyfrom: { type: Date },
  47. oemwarrantyto: { type: Date },
  48. //SERVICE PROVIDER
  49. warrantyfrom: { type: Date },
  50. warrantyto: { type: Date },
  51. serialno: { type: String },
  52. }],
  53.  
  54. prodregdate: { type: Date },
  55. //Details of Customer buying the product
  56. customer: {
  57. type: mongoose.Schema.Types.ObjectId,
  58. ref: "customer"
  59. },
  60. customertype: {
  61. type: mongoose.Schema.Types.ObjectId,
  62. ref: "customertype"
  63. },
  64. department: {
  65. type: mongoose.Schema.Types.ObjectId,
  66. ref: "customersubdepartment"
  67. },
  68. remarks: { type: String },
  69. entrydate: {
  70. type: Date,
  71. dafault: Date.now
  72. }
  73.  
  74. module.exports = ProductRegistration = mongoose.model('productregistration', ProductRegistrationSchema);
  75.  
  76. const express = require('express');
  77. const router = express.Router();
  78. const mongoose = require('mongoose');
  79.  
  80. const Product = require("../../../models/Master/Products");
  81. //importing the model of ProductRegistrationSchema
  82. const ProdReg = require('../../../models/Entries/ProductRegistration');
  83.  
  84. //Creating a new ProductRegistration Data
  85. router.post('/add', (req, res)=>{
  86. const newProdReg = new ProdReg({
  87. _id: new mongoose.Types.ObjectId(),
  88. refno1: req.body.refno1,
  89. refno2: req.body.refno2,
  90. prodregdate: req.body.prodregdate,
  91. data: {
  92. product: req.body.productid,
  93. oemwarrantyfrom: req.body.oemwarrantyfrom,
  94. oemwarrantyto: req.body.oemwarrantyto,
  95. warrantyfrom: req.body.warrantyfrom,
  96. warrantyto: req.body.warrantyto,
  97. serialno: req.body.serialno,
  98. },
  99. customer: req.body.customerid,
  100. customertype: req.body.customertypeid,
  101. department: req.body.customersubdepartmentid,
  102. remarks: req.body.remarks
  103. // deliverydate: req.body.deliverydate,
  104. // address: req.body.address,
  105. // assignedto: req.body.employeesid,
  106. // warrantyprovider: req.body.serviceproviderid,
  107. // oemwarrantyprovider: req.body.oemcompanyid,
  108. // warrantystartdate: req.body.warrantystartdate,
  109. // warrantyexpiredate: req.body.warrantyexpiredate,
  110.  
  111.  
  112. });
  113. newProdReg.save().then(prodreg => res.json(prodreg));
  114.  
  115. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement