Modified Assets to update the assetId in the history records when it gets changed. Changing the assetId is handy when a sticker is removed, making it possible to just alter the ID instead of re-printing the sticker.

This commit is contained in:
2023-07-30 14:11:12 -07:00
parent 2cbb4a47b5
commit 4d20bf73b7
6 changed files with 408 additions and 142 deletions

View File

@@ -123,6 +123,7 @@ Meteor.methods({
if(serial) check(serial, String);
check(condition, String);
if(conditionDetails) check(conditionDetails, String);
const existing = Assets.findOne({_id})
if(!conditions.includes(condition)) {
//Should never happen.
@@ -133,6 +134,12 @@ Meteor.methods({
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
//TODO: Need to first verify there are no checked out assets to the staff member.
Assets.update({_id}, {$set: {assetTypeId, assetId, serial, condition, conditionDetails}});
if(assetId !== existing.assetId) {
//When changing the asset id we also need to update the other locations in the data where that ID exists.
// assetAssignmentHistory.assetId
AssetAssignmentHistory.updateMany({assetId: existing.assetId}, {$set: {assetId}})
}
}
else throw new Meteor.Error("User Permission Error");
},
@@ -217,7 +224,7 @@ Meteor.methods({
throw new Meteor.Error("Asset is already assigned.", "Cannot assign an asset that has already been assigned.");
}
else {
Assets.update({assetId}, {$set: {assigneeType, assigneeId, assignmentDate: date, condition, conditionDetails}});
Assets.update({assetId}, {$set: {assigneeType, assigneeId, assignmentDate: date, condition, conditionDetails, assignedBy: Meteor.userId()}});
}
}
else {
@@ -257,11 +264,11 @@ Meteor.methods({
let assetType = AssetTypes.findOne({_id: asset.assetTypeId});
try {
AssetAssignmentHistory.insert({assetKey: asset._id, assetId, serial: asset.serial, assetTypeName: (assetType ? assetType.name : "UNK"), assigneeType: asset.assigneeType, assigneeId: asset.assigneeId, startDate: asset.assignmentDate, endDate: date, startCondition: asset.condition, endCondition: condition, startConditionDetails: asset.conditionDetails, endConditionDetails: conditionDetails, comment});
AssetAssignmentHistory.insert({assetKey: asset._id, assetId, serial: asset.serial, assetTypeName: (assetType ? assetType.name : "UNK"), assigneeType: asset.assigneeType, assigneeId: asset.assigneeId, startDate: asset.assignmentDate, endDate: date, startCondition: asset.condition, endCondition: condition, startConditionDetails: asset.conditionDetails, endConditionDetails: conditionDetails, comment, unassignedBy: Meteor.userId(), assignedBy: asset.assignedBy});
} catch (e) {
console.error(e);
}
Assets.update({assetId}, {$unset: {assigneeType: "", assigneeId: "", assignmentDate: ""}, $set: {condition, conditionDetails}});
Assets.update({assetId}, {$unset: {assigneeType: "", assigneeId: "", assignmentDate: "", assignedBy: ""}, $set: {condition, conditionDetails}});
}
else {
console.error("Could not find the asset: " + assetId);