Ciao , vorrei popolare un array di oggetti creato con Schema Mongoose 5, dato che la struttura è un po articolata ho creato dei sottooggetti. Ho provato anche a mettere default: undefined ma quando genero il modello , nel db "fasi" è sempre vuoto. Qualcuno può aiutarmi gentilmente?
Ecco il codice, vi ringrazio:
const mongoose = require('mongoose');
// Fasi
const DateSchema = { type: Date, default: new Date(false) };
const NumberSchema = { type: Number , default: 1 };
const StringSchema = { type: String, default: "" };
const CustomSchema = {
tempoaSchedaInOre: DateSchema,
tempoTotaleInOre: DateSchema,
tempoTotaleInMinuti: NumberSchema,
secNecessariPerUnaPCB: NumberSchema,
nomeOperatore: StringSchema,
costohOperatore: NumberSchema,
percSpesaSulTotale: NumberSchema,
costoFase: NumberSchema
};
// End Fasi
const preventiviSchema = mongoose.Schema({
cliente:{
type: String,
required: true
},
codice:{
type: String,
required: false
},
descrizione:{
type: String,
required: false
},
pcb : {
nSchede: { type: Number, required: true },
nSchedeInPCB: { type: Number, required: true },
nPCB: { type: Number, required: false }
},
smd: {
qtSmd: { type: Number, required: false},
qtFeeder: { type: Number, required: false},
tempoContMateriale: { type: Number, required: false},
tempoAttrezSerigrafia: { type: Number, required: false},
tempoAttrezPeP: { type: Number, required: false},
tempoSmontaggio: { type: Number, required: false},
tempoSerigrafia: { type: Number, required: false},
tempoAvvioProduzione: { type: Number, required: false},
pepChipH: { type: Number, required: false},
tempoRevisioneAoi: { type: Number, required: false},
qtSmdLatoB: { type: Number, required: false},
qtFeederLatoB: { type: Number, required: false},
tempoContMaterialeLatoB: { type: Number, required: false},
tempoAttrezSerigrafiaLatoB: { type: Number, required: false},
tempoAttrezPePLatoB: { type: Number, required: false},
tempoSmontaggioLatoB: { type: Number, required: false},
tempoAvvioProduzioneLatoB: { type: Number, required: false},
tempoSerigrafiaLatoB: { type: Number, required: false},
pepChipHLatoB: { type: Number, required: false},
tempoRevisioneAoiLatoB: { type: Number, required: false},
},
tht:{
qtTht: { type: Number, required: false},
qtTipolTht: { type: Number, required: false},
qtPthdaPreparare: { type: Number, required: false},
tempoDiPrepTht: { type: Number, required: false},
tempoControlloMateriale: { type: Number, required: false},
tempoMontaggioTht: { type: Number, required: false},
tempoSaldaturaOnda: { type: Number, required: false},
tempoSaldaturaaMano: { type: Number, required: false},
qntPuntiSaldaturaMano: { type: Number, required: false},
tempoMontaggioPonticelli: { type: Number, required: false},
qtPonticelliDaMontare: { type: Number, required: false},
modifica: { type: Number, required: false},
tempoDiRevisione: { type: Number, required: false},
rivettatura: { type: Number, required: false},
rivettatura2: { type: Number, required: false},
qtProtezione: { type: Number, required: false},
tempoProtezione: { type: Number, required: false},
targhette: { type: Number, required: false},
tropicalizzazione: { type: Number, required: false},
tempoSeparazioneSchede: { type: Number, required: false}
},
materialiDiConsumo:{
crema: { type: Number, required: false},
stagno: { type: Number, required: false},
rivetto: { type: Number, required: false},
kaptonInNastro: { type: Number, required: false},
bolliniKapton: { type: Number, required: false},
splicing: { type: Number, required: false},
spellicolabile: { type: Number, required: false},
tropicalizzante: { type: Number, required: false}
},
imballaggio:{
tempoDiImballaggio: { type: Number, required: false},
buste: { type: Number, required: false},
cartoni: { type: Number, required: false}
},
altreAttivita:{
modificheVarie: { type: Number, required: false},
numeroFlash: { type: Number, required: false},
programmazioneFlash: { type: Number, required: false},
componentiMeccanici: { type: Number, required: false},
collaudo: { type: Number, required: false}
},
data:{
type: Date,
default: Date.now
},
fase: {
type:[{
controlloMaterialeSmd : CustomSchema,
equipaggiamentoSerig : CustomSchema,
equipaggiamentoPeP : CustomSchema,
avvioProduzione : CustomSchema,
serigrafia : CustomSchema,
montaggioSmd : CustomSchema,
smontaggioPeP : CustomSchema,
revisioneAoi : CustomSchema,
equipaggiamentoSerigB : CustomSchema,
equipaggiamentoPePB : CustomSchema,
avvioProduzioneLatoB : CustomSchema,
serigrafiaLatoB : CustomSchema,
montaggioSmdLatoB : CustomSchema,
smontaggioPePLatoB : CustomSchema,
revisioneAoiLatoB : CustomSchema,
controlloMaterialeTHT: CustomSchema,
montaggioComponentiMec: CustomSchema,
preparazioneComponenti: CustomSchema,
rivettatura: CustomSchema,
giostra: CustomSchema,
protezioni: CustomSchema,
modifica: CustomSchema,
ponticello: CustomSchema,
saldaturaAdOnda: CustomSchema,
saldaturaAMano: CustomSchema,
revisione: CustomSchema,
collaudo: CustomSchema,
targhetta: CustomSchema,
separazioneSchede: CustomSchema,
tropicalizzazione: CustomSchema,
programmazioneFlash: CustomSchema,
imballaggio: CustomSchema,
totale: CustomSchema
}]
},
utente:{
type: String,
required: false
}
});
mongoose.model('preventivi',preventiviSchema);