express-ext 0.4.15 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +48 -71
- package/package.json +1 -1
- package/src/index.ts +55 -72
package/lib/index.js
CHANGED
|
@@ -40,31 +40,29 @@ __export(require("./search"))
|
|
|
40
40
|
__export(require("./SearchController"))
|
|
41
41
|
__export(require("./view"))
|
|
42
42
|
var SavedController = (function () {
|
|
43
|
-
function SavedController(
|
|
43
|
+
function SavedController(savedService, log, id, userId) {
|
|
44
|
+
this.savedService = savedService
|
|
44
45
|
this.log = log
|
|
45
|
-
this.
|
|
46
|
-
this.item = item
|
|
46
|
+
this.userId = userId && userId.length > 0 ? userId : "userId"
|
|
47
47
|
this.id = id && id.length > 0 ? id : "id"
|
|
48
48
|
this.save = this.save.bind(this)
|
|
49
49
|
this.remove = this.remove.bind(this)
|
|
50
|
-
this.load = this.load.bind(this)
|
|
51
50
|
}
|
|
52
51
|
SavedController.prototype.save = function (req, res) {
|
|
53
52
|
var _this = this
|
|
53
|
+
var userId = res.locals[this.userId]
|
|
54
54
|
var id = req.params[this.id]
|
|
55
|
-
var itemId = req.params[this.item]
|
|
56
55
|
if (!id || id.length === 0) {
|
|
57
|
-
res.status(400).end("'" + this.id + "' cannot be empty")
|
|
58
|
-
return
|
|
56
|
+
return res.status(400).end("'" + this.id + "' cannot be empty")
|
|
59
57
|
}
|
|
60
|
-
if (!
|
|
61
|
-
res.status(400).end("'" + this.
|
|
62
|
-
return
|
|
58
|
+
if (!userId || userId.length === 0) {
|
|
59
|
+
return res.status(400).end("'" + this.userId + "' cannot be empty")
|
|
63
60
|
}
|
|
64
|
-
this.
|
|
65
|
-
.save(
|
|
66
|
-
.then(function (
|
|
67
|
-
|
|
61
|
+
this.savedService
|
|
62
|
+
.save(userId, id)
|
|
63
|
+
.then(function (result) {
|
|
64
|
+
var status = result > 0 ? 200 : result === 0 ? 409 : 422
|
|
65
|
+
res.status(status).json(result).end()
|
|
68
66
|
})
|
|
69
67
|
.catch(function (err) {
|
|
70
68
|
return http_1.handleError(err, res, _this.log)
|
|
@@ -72,36 +70,19 @@ var SavedController = (function () {
|
|
|
72
70
|
}
|
|
73
71
|
SavedController.prototype.remove = function (req, res) {
|
|
74
72
|
var _this = this
|
|
73
|
+
var userId = res.locals[this.userId]
|
|
75
74
|
var id = req.params[this.id]
|
|
76
|
-
var itemId = req.params[this.item]
|
|
77
75
|
if (!id || id.length === 0) {
|
|
78
|
-
res.status(400).end("'" + this.id + "' cannot be empty")
|
|
79
|
-
return
|
|
76
|
+
return res.status(400).end("'" + this.id + "' cannot be empty")
|
|
80
77
|
}
|
|
81
|
-
if (!
|
|
82
|
-
res.status(400).end("'" + this.
|
|
83
|
-
return
|
|
78
|
+
if (!userId || userId.length === 0) {
|
|
79
|
+
return res.status(400).end("'" + this.userId + "' cannot be empty")
|
|
84
80
|
}
|
|
85
|
-
this.
|
|
86
|
-
.remove(
|
|
87
|
-
.then(function (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
.catch(function (err) {
|
|
91
|
-
return http_1.handleError(err, res, _this.log)
|
|
92
|
-
})
|
|
93
|
-
}
|
|
94
|
-
SavedController.prototype.load = function (req, res) {
|
|
95
|
-
var _this = this
|
|
96
|
-
var id = req.params[this.id]
|
|
97
|
-
if (!id || id.length === 0) {
|
|
98
|
-
res.status(400).end("'" + this.id + "' cannot be empty")
|
|
99
|
-
return
|
|
100
|
-
}
|
|
101
|
-
this.service
|
|
102
|
-
.load(id)
|
|
103
|
-
.then(function (data) {
|
|
104
|
-
res.status(200).json(data).end()
|
|
81
|
+
this.savedService
|
|
82
|
+
.remove(userId, id)
|
|
83
|
+
.then(function (result) {
|
|
84
|
+
var status = result > 0 ? 200 : 410
|
|
85
|
+
res.status(status).json(result).end()
|
|
105
86
|
})
|
|
106
87
|
.catch(function (err) {
|
|
107
88
|
return http_1.handleError(err, res, _this.log)
|
|
@@ -111,10 +92,10 @@ var SavedController = (function () {
|
|
|
111
92
|
})()
|
|
112
93
|
exports.SavedController = SavedController
|
|
113
94
|
var FollowController = (function () {
|
|
114
|
-
function FollowController(
|
|
115
|
-
this.log = log
|
|
95
|
+
function FollowController(service, log, id, userId) {
|
|
116
96
|
this.service = service
|
|
117
|
-
this.
|
|
97
|
+
this.log = log
|
|
98
|
+
this.userId = userId && userId.length > 0 ? userId : "userId"
|
|
118
99
|
this.id = id && id.length > 0 ? id : "id"
|
|
119
100
|
this.follow = this.follow.bind(this)
|
|
120
101
|
this.unfollow = this.unfollow.bind(this)
|
|
@@ -122,20 +103,19 @@ var FollowController = (function () {
|
|
|
122
103
|
}
|
|
123
104
|
FollowController.prototype.follow = function (req, res) {
|
|
124
105
|
var _this = this
|
|
125
|
-
var
|
|
126
|
-
var
|
|
106
|
+
var userId = res.locals[this.userId]
|
|
107
|
+
var id = req.params[this.id]
|
|
127
108
|
if (!id || id.length === 0) {
|
|
128
|
-
res.status(400).end("'" + this.id + "' cannot be empty")
|
|
129
|
-
return
|
|
109
|
+
return res.status(400).end("'" + this.id + "' cannot be empty")
|
|
130
110
|
}
|
|
131
|
-
if (!
|
|
132
|
-
res.status(400).end("'" + this.
|
|
133
|
-
return
|
|
111
|
+
if (!userId || userId.length === 0) {
|
|
112
|
+
return res.status(400).end("'" + this.userId + "' cannot be empty")
|
|
134
113
|
}
|
|
135
114
|
this.service
|
|
136
|
-
.follow(
|
|
137
|
-
.then(function (
|
|
138
|
-
|
|
115
|
+
.follow(userId, id)
|
|
116
|
+
.then(function (result) {
|
|
117
|
+
var status = result > 0 ? 200 : 409
|
|
118
|
+
res.status(status).json(result).end()
|
|
139
119
|
})
|
|
140
120
|
.catch(function (err) {
|
|
141
121
|
return http_1.handleError(err, res, _this.log)
|
|
@@ -143,20 +123,19 @@ var FollowController = (function () {
|
|
|
143
123
|
}
|
|
144
124
|
FollowController.prototype.unfollow = function (req, res) {
|
|
145
125
|
var _this = this
|
|
146
|
-
var
|
|
147
|
-
var
|
|
126
|
+
var userId = res.locals[this.userId]
|
|
127
|
+
var id = req.params[this.id]
|
|
148
128
|
if (!id || id.length === 0) {
|
|
149
|
-
res.status(400).end("'" + this.id + "' cannot be empty")
|
|
150
|
-
return
|
|
129
|
+
return res.status(400).end("'" + this.id + "' cannot be empty")
|
|
151
130
|
}
|
|
152
|
-
if (!
|
|
153
|
-
res.status(400).end("'" + this.
|
|
154
|
-
return
|
|
131
|
+
if (!userId || userId.length === 0) {
|
|
132
|
+
return res.status(400).end("'" + this.userId + "' cannot be empty")
|
|
155
133
|
}
|
|
156
134
|
this.service
|
|
157
|
-
.unfollow(
|
|
158
|
-
.then(function (
|
|
159
|
-
|
|
135
|
+
.unfollow(userId, id)
|
|
136
|
+
.then(function (result) {
|
|
137
|
+
var status = result > 0 ? 200 : 410
|
|
138
|
+
res.status(status).json(result).end()
|
|
160
139
|
})
|
|
161
140
|
.catch(function (err) {
|
|
162
141
|
return http_1.handleError(err, res, _this.log)
|
|
@@ -164,18 +143,16 @@ var FollowController = (function () {
|
|
|
164
143
|
}
|
|
165
144
|
FollowController.prototype.checkFollow = function (req, res) {
|
|
166
145
|
var _this = this
|
|
167
|
-
var
|
|
168
|
-
var
|
|
146
|
+
var userId = res.locals[this.userId]
|
|
147
|
+
var id = req.params[this.id]
|
|
169
148
|
if (!id || id.length === 0) {
|
|
170
|
-
res.status(400).end("'" + this.id + "' cannot be empty")
|
|
171
|
-
return
|
|
149
|
+
return res.status(400).end("'" + this.id + "' cannot be empty")
|
|
172
150
|
}
|
|
173
|
-
if (!
|
|
174
|
-
res.status(400).end("'" + this.
|
|
175
|
-
return
|
|
151
|
+
if (!userId || userId.length === 0) {
|
|
152
|
+
return res.status(400).end("'" + this.userId + "' cannot be empty")
|
|
176
153
|
}
|
|
177
154
|
this.service
|
|
178
|
-
.checkFollow(
|
|
155
|
+
.checkFollow(userId, id)
|
|
179
156
|
.then(function (count) {
|
|
180
157
|
return res.status(200).json(count).end()
|
|
181
158
|
})
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -42,132 +42,115 @@ export * from "./search"
|
|
|
42
42
|
export * from "./SearchController"
|
|
43
43
|
export * from "./view"
|
|
44
44
|
|
|
45
|
-
export interface SavedService
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
remove(id: string, itemId: string): Promise<number>
|
|
45
|
+
export interface SavedService {
|
|
46
|
+
save(userId: string, id: string): Promise<number>
|
|
47
|
+
remove(userId: string, id: string): Promise<number>
|
|
49
48
|
}
|
|
50
|
-
export class SavedController
|
|
51
|
-
constructor(
|
|
49
|
+
export class SavedController {
|
|
50
|
+
constructor(protected savedService: SavedService, protected log: (msg: string) => void, id?: string, userId?: string) {
|
|
51
|
+
this.userId = userId && userId.length > 0 ? userId : "userId"
|
|
52
52
|
this.id = id && id.length > 0 ? id : "id"
|
|
53
53
|
this.save = this.save.bind(this)
|
|
54
54
|
this.remove = this.remove.bind(this)
|
|
55
|
-
this.load = this.load.bind(this)
|
|
56
55
|
}
|
|
57
|
-
|
|
56
|
+
protected userId: string
|
|
57
|
+
protected id: string
|
|
58
58
|
save(req: Request, res: Response) {
|
|
59
|
+
const userId: string = res.locals[this.userId]
|
|
59
60
|
const id = req.params[this.id]
|
|
60
|
-
const itemId = req.params[this.item]
|
|
61
61
|
if (!id || id.length === 0) {
|
|
62
|
-
res.status(400).end(`'${this.id}' cannot be empty`)
|
|
63
|
-
return
|
|
62
|
+
return res.status(400).end(`'${this.id}' cannot be empty`)
|
|
64
63
|
}
|
|
65
|
-
if (!
|
|
66
|
-
res.status(400).end(`'${this.
|
|
67
|
-
return
|
|
64
|
+
if (!userId || userId.length === 0) {
|
|
65
|
+
return res.status(400).end(`'${this.userId}' cannot be empty`)
|
|
68
66
|
}
|
|
69
|
-
this.
|
|
70
|
-
.save(
|
|
71
|
-
.then((
|
|
72
|
-
|
|
67
|
+
this.savedService
|
|
68
|
+
.save(userId, id)
|
|
69
|
+
.then((result) => {
|
|
70
|
+
const status = result > 0 ? 200 : result === 0 ? 409 : 422
|
|
71
|
+
res.status(status).json(result).end()
|
|
73
72
|
})
|
|
74
73
|
.catch((err) => handleError(err, res, this.log))
|
|
75
74
|
}
|
|
76
75
|
remove(req: Request, res: Response) {
|
|
76
|
+
const userId: string = res.locals[this.userId]
|
|
77
77
|
const id = req.params[this.id]
|
|
78
|
-
const itemId = req.params[this.item]
|
|
79
78
|
if (!id || id.length === 0) {
|
|
80
|
-
res.status(400).end(`'${this.id}' cannot be empty`)
|
|
81
|
-
return
|
|
79
|
+
return res.status(400).end(`'${this.id}' cannot be empty`)
|
|
82
80
|
}
|
|
83
|
-
if (!
|
|
84
|
-
res.status(400).end(`'${this.
|
|
85
|
-
return
|
|
81
|
+
if (!userId || userId.length === 0) {
|
|
82
|
+
return res.status(400).end(`'${this.userId}' cannot be empty`)
|
|
86
83
|
}
|
|
87
|
-
this.
|
|
88
|
-
.remove(
|
|
89
|
-
.then((
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
.catch((err) => handleError(err, res, this.log))
|
|
93
|
-
}
|
|
94
|
-
load(req: Request, res: Response) {
|
|
95
|
-
const id = req.params[this.id]
|
|
96
|
-
if (!id || id.length === 0) {
|
|
97
|
-
res.status(400).end(`'${this.id}' cannot be empty`)
|
|
98
|
-
return
|
|
99
|
-
}
|
|
100
|
-
this.service
|
|
101
|
-
.load(id)
|
|
102
|
-
.then((data) => {
|
|
103
|
-
res.status(200).json(data).end()
|
|
84
|
+
this.savedService
|
|
85
|
+
.remove(userId, id)
|
|
86
|
+
.then((result) => {
|
|
87
|
+
const status = result > 0 ? 200 : 410
|
|
88
|
+
res.status(status).json(result).end()
|
|
104
89
|
})
|
|
105
90
|
.catch((err) => handleError(err, res, this.log))
|
|
106
91
|
}
|
|
107
92
|
}
|
|
108
93
|
export interface FollowService {
|
|
109
|
-
follow(id: string, target: string): Promise<number
|
|
94
|
+
follow(id: string, target: string): Promise<number>
|
|
110
95
|
unfollow(id: string, target: string): Promise<number>
|
|
111
96
|
checkFollow(id: string, target: string): Promise<number>
|
|
112
97
|
}
|
|
113
98
|
// tslint:disable-next-line:max-classes-per-file
|
|
114
99
|
export class FollowController {
|
|
115
|
-
constructor(
|
|
100
|
+
constructor(protected service: FollowService, protected log: Log, id?: string, userId?: string) {
|
|
101
|
+
this.userId = userId && userId.length > 0 ? userId : "userId"
|
|
116
102
|
this.id = id && id.length > 0 ? id : "id"
|
|
117
103
|
this.follow = this.follow.bind(this)
|
|
118
104
|
this.unfollow = this.unfollow.bind(this)
|
|
119
105
|
this.checkFollow = this.checkFollow.bind(this)
|
|
120
106
|
}
|
|
121
|
-
|
|
107
|
+
protected userId: string
|
|
108
|
+
protected id: string
|
|
122
109
|
follow(req: Request, res: Response): void {
|
|
123
|
-
const
|
|
124
|
-
const
|
|
110
|
+
const userId: string = res.locals[this.userId]
|
|
111
|
+
const id = req.params[this.id]
|
|
125
112
|
if (!id || id.length === 0) {
|
|
126
|
-
res.status(400).end(`'${this.id}' cannot be empty`)
|
|
127
|
-
return
|
|
113
|
+
return res.status(400).end(`'${this.id}' cannot be empty`)
|
|
128
114
|
}
|
|
129
|
-
if (!
|
|
130
|
-
res.status(400).end(`'${this.
|
|
131
|
-
return
|
|
115
|
+
if (!userId || userId.length === 0) {
|
|
116
|
+
return res.status(400).end(`'${this.userId}' cannot be empty`)
|
|
132
117
|
}
|
|
133
118
|
this.service
|
|
134
|
-
.follow(
|
|
135
|
-
.then((
|
|
136
|
-
|
|
119
|
+
.follow(userId, id)
|
|
120
|
+
.then((result) => {
|
|
121
|
+
const status = result > 0 ? 200 : 409
|
|
122
|
+
res.status(status).json(result).end()
|
|
137
123
|
})
|
|
138
124
|
.catch((err) => handleError(err, res, this.log))
|
|
139
125
|
}
|
|
140
126
|
unfollow(req: Request, res: Response): void {
|
|
141
|
-
const
|
|
142
|
-
const
|
|
127
|
+
const userId: string = res.locals[this.userId]
|
|
128
|
+
const id = req.params[this.id]
|
|
143
129
|
if (!id || id.length === 0) {
|
|
144
|
-
res.status(400).end(`'${this.id}' cannot be empty`)
|
|
145
|
-
return
|
|
130
|
+
return res.status(400).end(`'${this.id}' cannot be empty`)
|
|
146
131
|
}
|
|
147
|
-
if (!
|
|
148
|
-
res.status(400).end(`'${this.
|
|
149
|
-
return
|
|
132
|
+
if (!userId || userId.length === 0) {
|
|
133
|
+
return res.status(400).end(`'${this.userId}' cannot be empty`)
|
|
150
134
|
}
|
|
151
135
|
this.service
|
|
152
|
-
.unfollow(
|
|
153
|
-
.then((
|
|
154
|
-
|
|
136
|
+
.unfollow(userId, id)
|
|
137
|
+
.then((result) => {
|
|
138
|
+
const status = result > 0 ? 200 : 410
|
|
139
|
+
res.status(status).json(result).end()
|
|
155
140
|
})
|
|
156
141
|
.catch((err) => handleError(err, res, this.log))
|
|
157
142
|
}
|
|
158
143
|
checkFollow(req: Request, res: Response): void {
|
|
159
|
-
const
|
|
160
|
-
const
|
|
144
|
+
const userId: string = res.locals[this.userId]
|
|
145
|
+
const id = req.params[this.id]
|
|
161
146
|
if (!id || id.length === 0) {
|
|
162
|
-
res.status(400).end(`'${this.id}' cannot be empty`)
|
|
163
|
-
return
|
|
147
|
+
return res.status(400).end(`'${this.id}' cannot be empty`)
|
|
164
148
|
}
|
|
165
|
-
if (!
|
|
166
|
-
res.status(400).end(`'${this.
|
|
167
|
-
return
|
|
149
|
+
if (!userId || userId.length === 0) {
|
|
150
|
+
return res.status(400).end(`'${this.userId}' cannot be empty`)
|
|
168
151
|
}
|
|
169
152
|
this.service
|
|
170
|
-
.checkFollow(
|
|
153
|
+
.checkFollow(userId, id)
|
|
171
154
|
.then((count) => {
|
|
172
155
|
return res.status(200).json(count).end()
|
|
173
156
|
})
|