forked from pokers/backend_template
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathonelinerService.js
More file actions
82 lines (65 loc) · 1.81 KB
/
onelinerService.js
File metadata and controls
82 lines (65 loc) · 1.81 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
const {
OnelinerDao
} = require("../dao/onelinerDao");
const validator = require('validator')
const { InvalidUUID, AccountNotFound, MyBookNotFound } = require('./errorService');
class OnelinerService {
constructor(){
this._serviceName = 'onelinerService'
}
get serviceName(){
return this._serviceName
}
async postOneliner(data) {
const {
userId,
book_id,
title,
authors,
oneliner,
color,
top,
left,
font,
font_size,
bg_image_url
} = data;
// UUID type check
if (!validator.isUUID(userId)) {
throw new InvalidUUID(userId);
}
if (!validator.isUUID(book_id)) {
throw new InvalidUUID(book_id);
}
const onelinerDao = new OnelinerDao();
const onelinerRows = await onelinerDao.postOneliner(
userId,
book_id,
title,
authors,
oneliner,
color,
top,
left,
font,
font_size,
bg_image_url
);
return onelinerRows;
}
async getOneliner(userId, sortType, perPage, continuousToken){
const onelinerDao = new OnelinerDao()
const oneliner = await onelinerDao.getOneliner(userId, sortType, perPage, continuousToken)
return oneliner
}
async deleteOneliner(onelinerId){
// uuid type check
if (!validator.isUUID(onelinerId)){
throw new InvalidUUID(onelinerId)
}
const onelinerDao = new OnelinerDao()
const oneliner = await onelinerDao.deleteOnelinerByOnelinerId(onelinerId)
return oneliner
}
}
module.exports = { OnelinerService };