@ClementRicateau
cRicateau
import failed, file is incorrect. Please fix it and retry
Cheese.beginTransaction(
{
isolationLevel: Post.Transaction.READ_COMMITTED
}, function(err, tx) {
// Now we have a transaction (tx)
});
Cheese.import = function(file, callback) {
var tx;
tx = {};
return Model.startTransaction(tx, file)
.then(function() {
return Cheese.importProcess(tx, file);
})
.then(function() {
return tx.commit(function(err) {
return Cheese.exitAfterSuccess(callback);
});
})
.catch(function(err) {
return tx.rollback(function(rollbackError) {
return Cheese.exitAfterError(err, callback);
});
});
};
{
"_meta": {
...
"mixins": [
...
"./mixins"
]
}
}
Model.import = function(file, callback) {
var tx;
tx = {};
return Model.startTransaction(tx, file)
.then(function() {
return Model.importProcess(tx, file);
})
.then(function() {
return tx.commit(function(err) {
return Model.exitAfterSuccess(callback);
});
})
.catch(function(err) {
return tx.rollback(function(rollbackError) {
return Model.exitAfterError(err, callback);
});
});
};
Model.import = function(file, callback) {
var tx;
tx = {};
return Model.startTransaction(tx, file)
.then(function() {
return Model.importProcess(tx, file);
})
.then(function() {
return tx.commit(function(err) {
return Model.exitAfterSuccess(callback);
});
})
.catch(function(err) {
return tx.rollback(function(rollbackError) {
return Model.exitAfterError(err, callback);
});
});
};
{
"name": "Cheese",
"base": "PersistedModel",
"mixins": {
"Upload": {},
},
if (!Model.importLine) {
Model.importLine = function(line) {
return new Promise(function(resolve, reject) {
return resolve();
});
};
}
Cheese.importLine = function(transaction, line) {
return Cheese.findOne({
where: {
name: line.CheeseName
}
}, transaction
).then(function(foundCheese) {
var cheese;
cheese = {
name: line.CheeseName
};
if (foundCheese) {
cheese.id = cheese.id;
}
return Cheese.upsert(cheese, transaction);
});
};
{
"name": "Cheese",
"base": "PersistedModel",
"mixins": {
"Upload": {},
"CsvUpload": {
"requiredHeaders": [
"cheeseName",
"animalMilk"
],
"validators": {
"cheeseName": {
"required": true,
"type": "string"
},
"animalMilk": {
"required": true,
"type": "string"
}
}
},
module.exports = function(Model, options) {
if (!Model.validateLine) {
return Model.validateLine = function(line) {
return importService.validate(line, options.validators);
}
};
}
};
{
"name": "Cheese",
"base": "PersistedModel",
"mixins": {
"Upload": {},
"XlsUpload": {
"requiredHeaders": [
"cheeseName",
"animalMilk"
],
"validators": {
"cheeseName": {
"required": true,
"type": "string"
},
"animalMilk": {
"required": true,
"type": "string"
}
}
},
loopback-promisify
Loopback 3.0
Model.import = function(file, callback) {
var tx;
tx = {};
return Model.startTransaction(tx, file)
.then(function() {
return Model.importProcess(tx, file);
})
.then(function() {
return Model.exitAfterSuccess(callback);
});
})
.catch(function(err) {
return Model.exitAfterError(err, callback);
});
});
};