-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathalbumService.js
More file actions
46 lines (37 loc) · 1.1 KB
/
albumService.js
File metadata and controls
46 lines (37 loc) · 1.1 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
const nSQL = require("@nano-sql/core").nSQL;
const treatmentService = require('./treatmentService');
const getColumns = (key) => {
let columns = ["id", "name", "artist"];
const treatment = treatmentService.calculateTreatment(key);
if (treatment === 'on') {
columns.push('rating');
}
return columns;
};
const getAllAlbums = async (key) => {
const result = await nSQL("albums").query("select", getColumns(key)).exec();
return result;
};
const getAlbumById = async (key, id) => {
const result = await nSQL("albums").query("select", getColumns(key)).where(["id", "=", id]).exec();
return result;
};
const addAlbum = async (payload) => {
const result = await nSQL("albums").query("upsert", payload).exec();
return result;
};
const updateAlbum = async (payload) => {
const result = await nSQL("albums").query("upsert", payload).exec();
return result;
};
const deleteAlbum = async (id) => {
const result = await nSQL("albums").query("delete").where(["id", "=", id]).exec();
return result;
};
module.exports = {
getAllAlbums,
getAlbumById,
addAlbum,
updateAlbum,
deleteAlbum
};