-
Notifications
You must be signed in to change notification settings - Fork 0
/
claims.js
27 lines (24 loc) · 836 Bytes
/
claims.js
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
const fs = require('fs');
exports.checkCharacterClaim = function(name)
{
var claims = JSON.parse(fs.readFileSync('charclaims.json', 'utf8'));
var claim = claims.find(e => e['name'].toLowerCase() == name.toLowerCase());
return claim;
}
exports.claimCharacter = function(name, claimant)
{
var claims = JSON.parse(fs.readFileSync('charclaims.json', 'utf8'));
var claim = claims.find(e => e['name'].toLowerCase() == name.toLowerCase());
if (claim)
return claim;
claim = {'name': name, 'status': 1, 'claimant': claimant};
claims.push(claim);
fs.writeFileSync('charclaims.json', JSON.stringify(claims), 'utf8');
claim['status'] = 2;
return claim;
}
exports.listClaims = function(claimant)
{
var claims = JSON.parse(fs.readFileSync('charclaims.json', 'utf8'));
return claims.filter(e => e['claimant']['name'] == claimant);
}