-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentity.js
More file actions
83 lines (63 loc) · 2.11 KB
/
entity.js
File metadata and controls
83 lines (63 loc) · 2.11 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
73
74
75
76
77
78
79
80
81
82
83
// Crypto is used to generate the unique ID
const crypto = require('crypto');
class Dropzone {
constructor (name, likes, dislikes, img_src, img_description, kit_rental, ticket_cost, weather, min_licence, map_src, map_description, contacts) {
this.dropzone_id = this.generateUniqueID;
this.name = name;
this.likes = likes;
this.dislikes = dislikes;
this.img_src = img_src;
this.img_description = img_description;
this.kit_rental = kit_rental;
this.ticket_cost = ticket_cost;
this.weather = weather;
this.min_licence = min_licence;
this.map_src = map_src;
this.map_description = map_description;
this.contacts = contacts;
this.comments = {};
this.datapath = '/data/Dropzones.json';
}
/**
* Return list of all stored dropzones
* @returns {[Object]}
*/
async fetchEntities() {
const dzFle = await fs.promises.readFile(this.datapath);
// If no data exsists, return empty list
if (dzFle.toString('utf8') === '') return {dropzones: []};
const entityList = await JSON.parse(fileData);
return entityList;
}
/**
* Generates a unique id for a new instance of Dropzone
* @returns {string}
*/
generateUniqueID() {
// Thanks to stack overflow user Pono at https://stackoverflow.com/questions/23327010/how-to-generate-unique-id-with-node-js for thier post on how to implement it
let id = crypto.randomBytes(8).toString("hex");
return id;
}
}
module.exports.Dropzone = Dropzone;
/*
static createManyToOne (many, one) {
many.parent[one.name] = one;
const pluralName = many.name + 's'
one.child[pluralName] = many;
}
}
*/
/*
// File for creating nested entities
export class Entity {
constructor (name) {
this.name = name;
this.parent = {};
this.child = {};
}
/**
* Create the many to one relationship between entities
* @param {Entity} many The many entity in the many to one
* @param {Entity} one The one entity in the many to one
*/