I would like to know how I can make it so that I can edit vehicles, invoices, from this type of schema:
{
'mobile': String,
'customerData': {
city: String,
province: String,
street: String,
postalCode: String,
labourRate: String,
notes: String,
status: Boolean,
vehicles: [{
driverName: String,
plateNumber: String,
vin: String,
make: String,
model: String,
color: String,
body: String,
transmission: String,
engine: String,
year: String,
ac: Boolean,
invoices: [{
oilChange: Number,
date: Date,
number: String,
mileage: String,
discount: Number,
repairDescription: String,
totalAmount: Number,
}],
}],
},
'ownerData': {
garage: mongoose.Schema.Types.ObjectId,
},
'email': String,
'lastName': String,
'password': String,
'role': String,
'firstName': String,
}
So far, I’m able to edit the customer information, but what about when it’s a few levels deep?
This is my forest/users.js
file:
collection('users', {
actions: [],
fields: [{
field: 'city',
type: 'String',
get: (user) => {
return user.customerData.city;
},
set: ((user, value) => {
if (!user.customerData) {
user.customerData = {};
}
user.customerData.city = value;
})
}, {
field: 'province',
type: 'String',
get: (user) => {
return user.customerData.province;
},
set: ((user, value) => {
if (!user.customerData) {
user.customerData = {};
}
user.customerData.province = value;
})
}, {
field: 'street',
type: 'String',
get: (user) => {
return user.customerData.street;
},
set: ((user, value) => {
if (!user.customerData) {
user.customerData = {};
}
user.customerData.street = value;
})
}, {
field: 'postalCode',
type: 'String',
get: (user) => {
return user.customerData.postalCode;
},
set: ((user, value) => {
if (!user.customerData) {
user.customerData = {};
}
user.customerData.postalCode = value;
})
}, {
field: 'labourRate',
type: 'String',
get: (user) => {
return user.customerData.labourRate;
},
set: ((user, value) => {
if (!user.customerData) {
user.customerData = {};
}
user.customerData.labourRate = value;
})
}, {
field: 'notes',
type: 'String',
get: (user) => {
return user.customerData.notes;
},
set: ((user, value) => {
if (!user.customerData) {
user.customerData = {};
}
user.customerData.notes = value;
})
}, {
field: 'status',
type: 'Boolean',
get: (user) => {
return user.customerData.tatus;
},
set: ((user, value) => {
if (!user.customerData) {
user.customerData = {};
}
user.customerData.tatus = value;
})
}],
segments: [],
});