/
maintainer.js
76 lines (65 loc) 路 1.62 KB
/
maintainer.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
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
'use strict';
const orm = require('ormnomnom');
const joi = require('@hapi/joi');
const Package = require('./package');
const Namespace = require('./namespace');
module.exports = class Maintainer {
#package = null;
#namespace = null;
constructor({
id,
package_id,
package: pkg,
namespace_id,
namespace,
created,
modified,
active,
accepted
}) {
this.id = id;
this.package_id = package_id;
this.#package = pkg ? Promise.resolve(pkg) : null;
this.namespace_id = namespace_id;
this.#namespace = namespace ? Promise.resolve(namespace) : null;
this.created = created;
this.modified = modified;
this.active = active;
this.accepted = accepted;
}
get package() {
if (this.#package === null) {
this.#package = Package.objects.get({ id: this.package_id });
this.#package.catch(() => {});
}
return this.#package;
}
set package(p) {
this.#package = Promise.resolve(p);
this.package_id = this.#package.id;
}
get namespace() {
if (this.#namespace === null) {
this.#namespace = Namespace.objects.get({ id: this.namespace_id });
this.#namespace.catch(() => {});
}
return this.#namespace;
}
set namespace(n) {
this.#namespace = Promise.resolve(n);
this.namespace_id = this.#namespace.id;
}
};
module.exports.objects = orm(module.exports, {
id: joi
.number()
.integer()
.greater(-1)
.required(),
package: orm.fk(Package),
namespace: orm.fk(Namespace),
created: joi.date(),
modified: joi.date(),
active: joi.boolean().default(true),
accepted: joi.boolean().default(true)
});