-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsTuition.js
52 lines (43 loc) · 982 Bytes
/
sTuition.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
const models = require("../models");
const {throwException} = require("../global/helpers");
async function getTuition(id) {
const tuition = await models.Tuition.findByPk(id);
if(!tuition) {
throwException("E009");
}
return tuition;
}
async function getPagedTuition(offset, limit) {
const {count : total, rows} = await models.Tuition.findAndCountAll({
offset,
limit
});
const result = {
total,
rows,
count: rows.length
}
return result
}
async function getAllTuition() {
return await models.Tuition.findAll();
}
async function createTuition(data) {
await models.Tuition.create(data);
}
async function updateTuition(id, data) {
const tuition = await getTuition(id);
await tuition.update(data);
}
async function destroyTuition(id) {
const tuition = await getTuition(id);
await tuition.destroy();
}
module.exports = {
getTuition,
getAllTuition,
getPagedTuition,
createTuition,
updateTuition,
destroyTuition
}