-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSafeSchoolScript.js
More file actions
72 lines (57 loc) · 2.33 KB
/
Copy pathSafeSchoolScript.js
File metadata and controls
72 lines (57 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* global getAssetRegistry getFactory emit */
/**
* Sample transaction processor function.
* @param {org.example.basic.SampleTransaction} tx The sample transaction instance.
* @transaction
*/
async function sampleTransaction(tx) { // eslint-disable-line no-unused-vars
// Save the old value of the asset.
//const oldValue = tx.asset.value;
var d = Date(Date.now());
// Update the asset with the new value.
// tx.asset.value = tx.newValue;
// Get the asset registry for the asset.
const assetRegistry = await getAssetRegistry('org.example.basic.Issue');
// Get the Issue asset registry.
var list = await assetRegistry.getAll();
const IssueID = "ISS"+parseInt(list.length)+1;
// Create the Issue.
let Issue = getFactory().newResource('org.example.basic', 'Issue', IssueID);
Issue.details = tx.details;
Issue.reportedBy = tx.reportedBy;
Issue.timeStamp = String(d);
Issue.priority = tx.priority;
// Add the Issue to the Issue asset registry.
await assetRegistry.add(Issue);
// Update the asset in the asset registry.
//await assetRegistry.add(tx.asset);
// Emit an event for the Created Issue.
let event = getFactory().newEvent('org.example.basic', 'CreateIssue');
event.isanonymous = tx.isanonymous;
event.issueId = Issue.assetId;
event.totalIssues = parseInt(list.length)+1;
if (!event.isanonymous) {
event.reportedBy = tx.reportedBy;
}
else
{
const participantRegistry = await getParticipantRegistry('org.example.basic.SampleParticipant');
//let participant = getFactory().participantRegistry.get("ANMS")
event.reportedBy = await participantRegistry.get("ANMS") ;
}
event.asset = Issue;
emit(event);
}