Initial cut - untested.
This commit is contained in:
@@ -84,7 +84,7 @@ if (Meteor.isServer) {
|
||||
});
|
||||
}
|
||||
Meteor.methods({
|
||||
'assets.add'(assetTypeId, assetId, serial, condition, conditionDetails) {
|
||||
async 'assets.add'(assetTypeId, assetId, serial, condition, conditionDetails) {
|
||||
check(assetTypeId, String);
|
||||
check(assetId, String);
|
||||
check(serial, String);
|
||||
@@ -101,29 +101,29 @@ Meteor.methods({
|
||||
assetId = assetId.toUpperCase();
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
let assetType = AssetTypes.findOne({assetTypeId});
|
||||
let assetType = await AssetTypes.findOneAsync({assetTypeId});
|
||||
|
||||
if(Assets.findOne({assetId})) {
|
||||
if(await Assets.findOneAsync({assetId})) {
|
||||
//return {error: true, errorType: 'duplicateAssetId'}
|
||||
throw new Meteor.Error("Duplicate Asset Id", "Cannot use the same asset ID twice.")
|
||||
}
|
||||
else if(serial) {
|
||||
Assets.insert({assetTypeId, assetId, serial, condition, conditionDetails});
|
||||
await Assets.insertAsync({assetTypeId, assetId, serial, condition, conditionDetails});
|
||||
}
|
||||
else {
|
||||
Assets.insert({assetTypeId, assetId, condition, conditionDetails});
|
||||
await Assets.insertAsync({assetTypeId, assetId, condition, conditionDetails});
|
||||
}
|
||||
}
|
||||
else throw new Meteor.Error("User Permission Error");
|
||||
},
|
||||
'assets.update'(_id, assetTypeId, assetId, serial, condition, conditionDetails) {
|
||||
async 'assets.update'(_id, assetTypeId, assetId, serial, condition, conditionDetails) {
|
||||
check(_id, String);
|
||||
check(assetTypeId, String);
|
||||
check(assetId, String);
|
||||
if(serial) check(serial, String);
|
||||
check(condition, String);
|
||||
if(conditionDetails) check(conditionDetails, String);
|
||||
const existing = Assets.findOne({_id})
|
||||
const existing = await Assets.findOneAsync({_id})
|
||||
|
||||
if(!conditions.includes(condition)) {
|
||||
//Should never happen.
|
||||
@@ -133,17 +133,17 @@ 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}});
|
||||
await Assets.updateAsync({_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}})
|
||||
await AssetAssignmentHistory.updateManyAsync({assetId: existing.assetId}, {$set: {assetId}})
|
||||
}
|
||||
}
|
||||
else throw new Meteor.Error("User Permission Error");
|
||||
},
|
||||
'assets.updateCondition'(_id, condition, conditionDetails) {
|
||||
async 'assets.updateCondition'(_id, condition, conditionDetails) {
|
||||
console.log("updating condtition: " + condition + " / " + conditionDetails)
|
||||
check(_id, String)
|
||||
check(condition, String)
|
||||
@@ -157,15 +157,15 @@ Meteor.methods({
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "laptop-management", {anyScope:true})) {
|
||||
console.log("updating .... ")
|
||||
Assets.update({_id}, {$set: {condition, conditionDetails}});
|
||||
await Assets.updateAsync({_id}, {$set: {condition, conditionDetails}});
|
||||
}
|
||||
else throw new Meteor.Error("User Permission Error");
|
||||
},
|
||||
'assets.remove'(_id) {
|
||||
async 'assets.remove'(_id) {
|
||||
check(_id, String);
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
let asset = Assets.findOne({_id});
|
||||
let asset = await Assets.findOneAsync({_id});
|
||||
|
||||
if(asset) {
|
||||
// Ensure the asset is not assigned still. Must unassign then remove. That allows us to maintain historical records for assignees.
|
||||
@@ -173,7 +173,7 @@ Meteor.methods({
|
||||
throw new Meteor.Error("Must unassign the asset before removal.");
|
||||
}
|
||||
else {
|
||||
Assets.remove({_id});
|
||||
await Assets.removeAsync({_id});
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -192,7 +192,7 @@ Meteor.methods({
|
||||
* @param conditionDetails A text block detailing the current condition (if it is needed).
|
||||
* @param date The date/time of the action. Will be set to the current date/time if not provided.
|
||||
*/
|
||||
'assets.assign'(assetId, assigneeType, assigneeId, condition, conditionDetails, date) {
|
||||
async 'assets.assign'(assetId, assigneeType, assigneeId, condition, conditionDetails, date) {
|
||||
check(assigneeId, String);
|
||||
check(assigneeType, String);
|
||||
check(assetId, String);
|
||||
@@ -215,7 +215,7 @@ Meteor.methods({
|
||||
throw new Meteor.Error("Error: Received incorrect assignee type in adding an assignment.");
|
||||
}
|
||||
else if(Roles.userIsInRole(Meteor.userId(), "laptop-management", {anyScope:true})) {
|
||||
let asset = Assets.findOne({assetId});
|
||||
let asset = await Assets.findOneAsync({assetId});
|
||||
|
||||
if(asset) {
|
||||
if(asset.assigneeId) {
|
||||
@@ -224,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, assignedBy: Meteor.userId()}});
|
||||
await Assets.updateAsync({assetId}, {$set: {assigneeType, assigneeId, assignmentDate: date, condition, conditionDetails, assignedBy: Meteor.userId()}});
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -242,7 +242,7 @@ Meteor.methods({
|
||||
* @param conditionDetails A text block detailing the current condition (if it is needed).
|
||||
* @param date The date/time of the action. Will be set to the current date/time if not provided.
|
||||
*/
|
||||
'assets.unassign'(assetId, comment, condition, conditionDetails, date) {
|
||||
async 'assets.unassign'(assetId, comment, condition, conditionDetails, date) {
|
||||
check(assetId, String);
|
||||
if(date) check(date, Date);
|
||||
if(comment) check(comment, String);
|
||||
@@ -258,17 +258,17 @@ Meteor.methods({
|
||||
}
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "laptop-management", {anyScope:true})) {
|
||||
let asset = Assets.findOne({assetId});
|
||||
let asset = await Assets.findOneAsync({assetId});
|
||||
|
||||
if(asset) {
|
||||
let assetType = AssetTypes.findOne({_id: asset.assetTypeId});
|
||||
let assetType = await AssetTypes.findOneAsync({_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, unassignedBy: Meteor.userId(), assignedBy: asset.assignedBy});
|
||||
await AssetAssignmentHistory.insertAsync({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: "", assignedBy: ""}, $set: {condition, conditionDetails}});
|
||||
await Assets.updateAsync({assetId}, {$unset: {assigneeType: "", assigneeId: "", assignmentDate: "", assignedBy: ""}, $set: {condition, conditionDetails}});
|
||||
}
|
||||
else {
|
||||
console.error("Could not find the asset: " + assetId);
|
||||
@@ -280,7 +280,9 @@ Meteor.methods({
|
||||
/**
|
||||
* A fix to remove the AssetAssignment collection and merge it with the Asset collection.
|
||||
*/
|
||||
'assets.fixAssetAssignments'() {
|
||||
async 'assets.fixAssetAssignments'() {
|
||||
//Note: Did not update this to Meteor 3.0
|
||||
|
||||
// Removed this since it should no longer be relevant.
|
||||
|
||||
// let assignmentDate = new Date();
|
||||
@@ -310,17 +312,17 @@ Meteor.methods({
|
||||
/**
|
||||
* A fix to remove the AssetAssignment collection and merge it with the Asset collection.
|
||||
*/
|
||||
'assets.fixAssetCondition'() {
|
||||
async 'assets.fixAssetCondition'() {
|
||||
// Removed this since it should no longer be relevant.
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
Assets.update({assetTypeId: 'xPu8YK39pmQW93Fuz', condition: {$exists: false}}, {$set: {condition: 'Okay', conditionDetails: 'Automated Condition'}}, {multi: true}); //Lenovo E100 CB
|
||||
Assets.update({assetTypeId: 'casMp4pJ9t8FtpyuR', condition: {$exists: false}}, {$set: {condition: 'Good', conditionDetails: 'Automated Condition'}}, {multi: true}); //Lenovo E100 Charger
|
||||
Assets.update({assetTypeId: 'ZD9XiHqGr6TcKH9Nv', condition: {$exists: false}}, {$set: {condition: 'New'}}, {multi: true}); //Acer CB315 CB
|
||||
Assets.update({assetTypeId: 'mfE9NtiFBotb8kp4v', condition: {$exists: false}}, {$set: {condition: 'New'}}, {multi: true}); //Acer CB315 Charger
|
||||
Assets.update({assetTypeId: 'btEsKYxW4Sgf7T8nA', condition: {$exists: false}}, {$set: {condition: 'Good',conditionDetails: 'Automated Condition'}}, {multi: true}); //Dell 3100 Charger
|
||||
Assets.update({assetTypeId: '9bszeFJNPteMDbye5', condition: {$exists: false}}, {$set: {condition: 'Like New',conditionDetails: 'Automated Condition'}}, {multi: true}); //HP 11A CB
|
||||
Assets.update({assetTypeId: 'tCj7s5T2YcFXZEaqE', condition: {$exists: false}}, {$set: {condition: 'Like New',conditionDetails: 'Automated Condition'}}, {multi: true}); //HP 11A Charger
|
||||
await Assets.updateAsync({assetTypeId: 'xPu8YK39pmQW93Fuz', condition: {$exists: false}}, {$set: {condition: 'Okay', conditionDetails: 'Automated Condition'}}, {multi: true}); //Lenovo E100 CB
|
||||
await Assets.updateAsync({assetTypeId: 'casMp4pJ9t8FtpyuR', condition: {$exists: false}}, {$set: {condition: 'Good', conditionDetails: 'Automated Condition'}}, {multi: true}); //Lenovo E100 Charger
|
||||
await Assets.updateAsync({assetTypeId: 'ZD9XiHqGr6TcKH9Nv', condition: {$exists: false}}, {$set: {condition: 'New'}}, {multi: true}); //Acer CB315 CB
|
||||
await Assets.updateAsync({assetTypeId: 'mfE9NtiFBotb8kp4v', condition: {$exists: false}}, {$set: {condition: 'New'}}, {multi: true}); //Acer CB315 Charger
|
||||
await Assets.updateAsync({assetTypeId: 'btEsKYxW4Sgf7T8nA', condition: {$exists: false}}, {$set: {condition: 'Good',conditionDetails: 'Automated Condition'}}, {multi: true}); //Dell 3100 Charger
|
||||
await Assets.updateAsync({assetTypeId: '9bszeFJNPteMDbye5', condition: {$exists: false}}, {$set: {condition: 'Like New',conditionDetails: 'Automated Condition'}}, {multi: true}); //HP 11A CB
|
||||
await Assets.updateAsync({assetTypeId: 'tCj7s5T2YcFXZEaqE', condition: {$exists: false}}, {$set: {condition: 'Like New',conditionDetails: 'Automated Condition'}}, {multi: true}); //HP 11A Charger
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user