payservedb 5.2.4 → 5.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payservedb",
3
- "version": "5.2.4",
3
+ "version": "5.2.6",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -1,109 +1,72 @@
1
1
  const mongoose = require('mongoose');
2
2
 
3
3
  const rfqResponseSchema = new mongoose.Schema({
4
- facilityId: {
5
- type: mongoose.Schema.Types.ObjectId,
6
- ref: 'Facility',
7
- required: true,
8
- index: true,
4
+ facilityId: {
5
+ type: mongoose.Schema.Types.ObjectId,
6
+ ref: 'Facility',
7
+ required: true,
8
+ index: true,
9
+ },
10
+ rfqId: {
11
+ type: mongoose.Schema.Types.ObjectId,
12
+ ref: 'RFQDetails',
13
+ required: true,
14
+ index: true,
15
+ },
16
+ supplierId: {
17
+ type: mongoose.Schema.Types.ObjectId,
18
+ ref: 'Supplier',
19
+ required: true,
20
+ index: true,
21
+ },
22
+
23
+ items: [{
24
+ itemId: {
25
+ type: mongoose.Schema.Types.ObjectId,
26
+ required: true,
27
+ },
28
+ unitPrice: {
29
+ type: Number,
30
+ required: true,
31
+ min: 0,
9
32
  },
10
- rfqId: {
11
- type: mongoose.Schema.Types.ObjectId,
12
- ref: 'RFQDetails',
13
- required: true,
14
- unique: true,
15
- index: true,
33
+ quantity: {
34
+ type: Number,
35
+ required: true,
36
+ min: 1,
16
37
  },
38
+ totalPrice: {
39
+ type: Number,
40
+ required: true,
41
+ min: 0,
42
+ },
43
+ }],
17
44
 
18
- // track each supplier’s progress & quotation
19
- suppliers: [{
20
- supplierId: {
21
- type: mongoose.Schema.Types.ObjectId,
22
- ref: 'Supplier',
23
- required: true,
24
- },
25
- invitationStatus: {
26
- type: String,
27
- enum: ['pending', 'accepted', 'declined', 'no-response'],
28
- default: 'pending',
29
- },
30
- invitationDate: {
31
- type: Date,
32
- default: Date.now,
33
- },
34
- responseDate: Date,
35
- quotationSubmitted: {
36
- type: Boolean,
37
- default: false,
38
- },
39
- quotationDetails: {
40
- submissionDate: Date,
41
- totalAmount: Number,
42
- items: [{
43
- // tie back to the Details’ item index or category
44
- categoryId: { type: mongoose.Schema.Types.ObjectId, required: true },
45
- itemId: { type: mongoose.Schema.Types.ObjectId, required: true },
46
- unitPrice: { type: Number, required: true },
47
- quantity: { type: Number, required: true },
48
- totalPrice: { type: Number, required: true },
49
- notes: { type: String, trim: true },
50
- }],
51
- attachments: [{
52
- name: { type: String, required: true },
53
- fileType: { type: String, required: true },
54
- filePath: { type: String, required: true },
55
- uploadDate: { type: Date, default: Date.now },
56
- }],
57
- notes: { type: String, trim: true },
58
- },
59
- evaluationScore: { type: Number, min: 0, max: 100 },
60
- evaluationNotes: { type: String, trim: true },
61
- }],
45
+ status: {
46
+ type: String,
47
+ enum: ['pending', 'submitted', 'evaluated', 'awarded'],
48
+ default: 'pending',
49
+ index: true,
50
+ },
62
51
 
63
- // overall lifecycle & award
64
- status: {
65
- type: String,
66
- enum: ['open', 'closed', 'awarded', 'canceled'],
67
- default: 'open',
68
- index: true,
52
+ evaluation: {
53
+ score: {
54
+ type: Number,
55
+ min: 0,
56
+ max: 100,
57
+ default: null,
69
58
  },
70
- awardDetails: {
71
- awarded: {
72
- type: Boolean,
73
- default: false,
74
- },
75
- awardedSupplierId: {
76
- type: mongoose.Schema.Types.ObjectId,
77
- ref: 'Supplier',
78
- },
79
- awardedSupplierName: {
80
- type: String,
81
- trim: true,
82
- },
83
- awardDate: Date,
84
- awardNotes: { type: String, trim: true },
85
-
86
- purchaseOrderCreated: {
87
- type: Boolean,
88
- default: false,
89
- },
90
- purchaseOrderId: {
91
- type: mongoose.Schema.Types.ObjectId,
92
- ref: 'PurchaseOrder',
93
- },
59
+ notes: {
60
+ type: String,
61
+ trim: true,
62
+ default: ''
94
63
  },
95
-
64
+ },
96
65
  }, {
97
- timestamps: true,
98
- });
99
-
100
- // participation rate virtual
101
- rfqResponseSchema.virtual('participationRate').get(function () {
102
- if (!this.suppliers.length) return 0;
103
- const responded = this.suppliers.filter(s => s.quotationSubmitted).length;
104
- return (responded / this.suppliers.length) * 100;
66
+ timestamps: true,
105
67
  });
106
68
 
107
- const RFQResponse = mongoose.model('RFQResponse', rfqResponseSchema);
69
+ // Unique response per supplier per RFQ
70
+ rfqResponseSchema.index({ rfqId: 1, supplierId: 1 }, { unique: true });
108
71
 
109
- module.exports = RFQResponse;
72
+ module.exports = mongoose.model('RFQResponse', rfqResponseSchema);