express-ext 0.1.30 → 0.1.33
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 +79 -5
- package/package.json +1 -1
- package/src/index.ts +78 -6
package/lib/index.js
CHANGED
|
@@ -78,7 +78,7 @@ var SavedController = (function () {
|
|
|
78
78
|
this.item = item;
|
|
79
79
|
this.id = (id && id.length > 0 ? id : 'id');
|
|
80
80
|
this.save = this.save.bind(this);
|
|
81
|
-
this.
|
|
81
|
+
this.remove = this.remove.bind(this);
|
|
82
82
|
this.load = this.load.bind(this);
|
|
83
83
|
}
|
|
84
84
|
SavedController.prototype.save = function (req, res) {
|
|
@@ -98,7 +98,7 @@ var SavedController = (function () {
|
|
|
98
98
|
})
|
|
99
99
|
.catch(function (err) { return http_1.handleError(err, res, _this.log); });
|
|
100
100
|
};
|
|
101
|
-
SavedController.prototype.
|
|
101
|
+
SavedController.prototype.remove = function (req, res) {
|
|
102
102
|
var _this = this;
|
|
103
103
|
var id = req.params[this.id];
|
|
104
104
|
var itemId = req.params[this.item];
|
|
@@ -110,7 +110,7 @@ var SavedController = (function () {
|
|
|
110
110
|
res.status(400).end("'" + this.item + "' cannot be empty");
|
|
111
111
|
return;
|
|
112
112
|
}
|
|
113
|
-
this.service.
|
|
113
|
+
this.service.remove(id, itemId).then(function (data) {
|
|
114
114
|
res.status(200).json(data).end();
|
|
115
115
|
})
|
|
116
116
|
.catch(function (err) { return http_1.handleError(err, res, _this.log); });
|
|
@@ -138,7 +138,7 @@ var FollowController = (function () {
|
|
|
138
138
|
this.id = (id && id.length > 0 ? id : 'id');
|
|
139
139
|
this.follow = this.follow.bind(this);
|
|
140
140
|
this.unfollow = this.unfollow.bind(this);
|
|
141
|
-
this.
|
|
141
|
+
this.checkFollow = this.checkFollow.bind(this);
|
|
142
142
|
}
|
|
143
143
|
FollowController.prototype.follow = function (req, res) {
|
|
144
144
|
var _this = this;
|
|
@@ -172,7 +172,7 @@ var FollowController = (function () {
|
|
|
172
172
|
return res.status(200).json(count).end();
|
|
173
173
|
}).catch(function (err) { return http_1.handleError(err, res, _this.log); });
|
|
174
174
|
};
|
|
175
|
-
FollowController.prototype.
|
|
175
|
+
FollowController.prototype.checkFollow = function (req, res) {
|
|
176
176
|
var _this = this;
|
|
177
177
|
var id = req.params.id;
|
|
178
178
|
var target = req.params.target;
|
|
@@ -191,3 +191,77 @@ var FollowController = (function () {
|
|
|
191
191
|
return FollowController;
|
|
192
192
|
}());
|
|
193
193
|
exports.FollowController = FollowController;
|
|
194
|
+
var ReactionController = (function () {
|
|
195
|
+
function ReactionController(log, service, author, id, reaction) {
|
|
196
|
+
this.log = log;
|
|
197
|
+
this.service = service;
|
|
198
|
+
this.author = author;
|
|
199
|
+
this.reaction = reaction;
|
|
200
|
+
this.id = (id && id.length > 0 ? id : 'id');
|
|
201
|
+
this.react = this.react.bind(this);
|
|
202
|
+
this.unreact = this.unreact.bind(this);
|
|
203
|
+
this.checkReaction = this.checkReaction.bind(this);
|
|
204
|
+
}
|
|
205
|
+
ReactionController.prototype.react = function (req, res) {
|
|
206
|
+
var _this = this;
|
|
207
|
+
var id = req.params.id;
|
|
208
|
+
var author = req.params.author;
|
|
209
|
+
var reaction = req.params.reaction;
|
|
210
|
+
if (!id || id.length === 0) {
|
|
211
|
+
res.status(400).end("'" + this.id + "' cannot be empty");
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (!author || author.length === 0) {
|
|
215
|
+
res.status(400).end("'" + this.author + "' cannot be empty");
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (!reaction || reaction.length === 0) {
|
|
219
|
+
res.status(400).end("'" + this.reaction + "' cannot be empty");
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
this.service.react(id, author, reaction).then(function (count) {
|
|
223
|
+
return res.status(200).json(count).end();
|
|
224
|
+
}).catch(function (err) { return http_1.handleError(err, res, _this.log); });
|
|
225
|
+
};
|
|
226
|
+
ReactionController.prototype.unreact = function (req, res) {
|
|
227
|
+
var _this = this;
|
|
228
|
+
var id = req.params.id;
|
|
229
|
+
var author = req.params.author;
|
|
230
|
+
var reaction = req.params.reaction;
|
|
231
|
+
if (!id || id.length === 0) {
|
|
232
|
+
res.status(400).end("'" + this.id + "' cannot be empty");
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
if (!author || author.length === 0) {
|
|
236
|
+
res.status(400).end("'" + this.author + "' cannot be empty");
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (!reaction || reaction.length === 0) {
|
|
240
|
+
res.status(400).end("'" + this.reaction + "' cannot be empty");
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
this.service.unreact(id, author, reaction).then(function (count) {
|
|
244
|
+
return res.status(200).json(count).end();
|
|
245
|
+
}).catch(function (err) { return http_1.handleError(err, res, _this.log); });
|
|
246
|
+
};
|
|
247
|
+
ReactionController.prototype.checkReaction = function (req, res) {
|
|
248
|
+
var _this = this;
|
|
249
|
+
var id = req.params.id;
|
|
250
|
+
var author = req.params.author;
|
|
251
|
+
if (!id || id.length === 0) {
|
|
252
|
+
res.status(400).end("'" + this.id + "' cannot be empty");
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
if (!author || author.length === 0) {
|
|
256
|
+
res.status(400).end("'" + this.author + "' cannot be empty");
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
this.service.checkReaction(id, author).then(function (count) {
|
|
260
|
+
return res.status(200).json(count).end();
|
|
261
|
+
}).catch(function (err) { return http_1.handleError(err, res, _this.log); });
|
|
262
|
+
};
|
|
263
|
+
return ReactionController;
|
|
264
|
+
}());
|
|
265
|
+
exports.ReactionController = ReactionController;
|
|
266
|
+
exports.ReactController = ReactionController;
|
|
267
|
+
exports.UserReactionController = ReactionController;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -83,13 +83,13 @@ export function allow(access: AccessConfig): (req: Request, res: Response, next:
|
|
|
83
83
|
export interface SavedService<T> {
|
|
84
84
|
load(id: string): Promise<T[]>;
|
|
85
85
|
save(id: string, itemId: string): Promise<number>;
|
|
86
|
-
|
|
86
|
+
remove(id: string, itemId: string): Promise<number>;
|
|
87
87
|
}
|
|
88
88
|
export class SavedController<T> {
|
|
89
89
|
constructor(public log: (msg: string) => void, public service: SavedService<T>, public item: string, id?: string) {
|
|
90
90
|
this.id = (id && id.length > 0 ? id : 'id');
|
|
91
91
|
this.save = this.save.bind(this);
|
|
92
|
-
this.
|
|
92
|
+
this.remove = this.remove.bind(this);
|
|
93
93
|
this.load = this.load.bind(this);
|
|
94
94
|
}
|
|
95
95
|
id: string;
|
|
@@ -109,7 +109,7 @@ export class SavedController<T> {
|
|
|
109
109
|
})
|
|
110
110
|
.catch(err => handleError(err, res, this.log));
|
|
111
111
|
}
|
|
112
|
-
|
|
112
|
+
remove(req: Request, res: Response) {
|
|
113
113
|
const id = req.params[this.id];
|
|
114
114
|
const itemId = req.params[this.item];
|
|
115
115
|
if (!id || id.length === 0) {
|
|
@@ -120,7 +120,7 @@ export class SavedController<T> {
|
|
|
120
120
|
res.status(400).end(`'${this.item}' cannot be empty`);
|
|
121
121
|
return;
|
|
122
122
|
}
|
|
123
|
-
this.service.
|
|
123
|
+
this.service.remove(id, itemId).then(data => {
|
|
124
124
|
res.status(200).json(data).end();
|
|
125
125
|
})
|
|
126
126
|
.catch(err => handleError(err, res, this.log));
|
|
@@ -148,7 +148,7 @@ export class FollowController {
|
|
|
148
148
|
this.id = (id && id.length > 0 ? id : 'id');
|
|
149
149
|
this.follow = this.follow.bind(this);
|
|
150
150
|
this.unfollow = this.unfollow.bind(this);
|
|
151
|
-
this.
|
|
151
|
+
this.checkFollow = this.checkFollow.bind(this);
|
|
152
152
|
}
|
|
153
153
|
id: string;
|
|
154
154
|
follow(req: Request, res: Response): void {
|
|
@@ -181,7 +181,7 @@ export class FollowController {
|
|
|
181
181
|
return res.status(200).json(count).end();
|
|
182
182
|
}).catch(err => handleError(err, res, this.log));
|
|
183
183
|
}
|
|
184
|
-
|
|
184
|
+
checkFollow(req: Request, res: Response): void {
|
|
185
185
|
const id = req.params.id;
|
|
186
186
|
const target = req.params.target;
|
|
187
187
|
if (!id || id.length === 0) {
|
|
@@ -197,3 +197,75 @@ export class FollowController {
|
|
|
197
197
|
}).catch(err => handleError(err, res, this.log));
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
|
+
export interface ReactService {
|
|
201
|
+
react(id: string, author: string, reaction: string): Promise<number>;
|
|
202
|
+
unreact(id: string, author: string, reaction: string): Promise<number>;
|
|
203
|
+
checkReaction(id: string, author: string): Promise<number>;
|
|
204
|
+
}
|
|
205
|
+
// tslint:disable-next-line:max-classes-per-file
|
|
206
|
+
export class ReactionController {
|
|
207
|
+
constructor(public log: Log, public service: ReactService, public author: string, id: string, public reaction: string) {
|
|
208
|
+
this.id = (id && id.length > 0 ? id : 'id');
|
|
209
|
+
this.react = this.react.bind(this);
|
|
210
|
+
this.unreact = this.unreact.bind(this);
|
|
211
|
+
this.checkReaction = this.checkReaction.bind(this);
|
|
212
|
+
}
|
|
213
|
+
id: string;
|
|
214
|
+
react(req: Request, res: Response): void {
|
|
215
|
+
const id = req.params.id;
|
|
216
|
+
const author = req.params.author;
|
|
217
|
+
const reaction = req.params.reaction;
|
|
218
|
+
if (!id || id.length === 0) {
|
|
219
|
+
res.status(400).end(`'${this.id}' cannot be empty`);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (!author || author.length === 0) {
|
|
223
|
+
res.status(400).end(`'${this.author}' cannot be empty`);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (!reaction || reaction.length === 0) {
|
|
227
|
+
res.status(400).end(`'${this.reaction}' cannot be empty`);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
this.service.react(id, author, reaction).then(count => {
|
|
231
|
+
return res.status(200).json(count).end();
|
|
232
|
+
}).catch(err => handleError(err, res, this.log));
|
|
233
|
+
}
|
|
234
|
+
unreact(req: Request, res: Response): void {
|
|
235
|
+
const id = req.params.id;
|
|
236
|
+
const author = req.params.author;
|
|
237
|
+
const reaction = req.params.reaction;
|
|
238
|
+
if (!id || id.length === 0) {
|
|
239
|
+
res.status(400).end(`'${this.id}' cannot be empty`);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
if (!author || author.length === 0) {
|
|
243
|
+
res.status(400).end(`'${this.author}' cannot be empty`);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (!reaction || reaction.length === 0) {
|
|
247
|
+
res.status(400).end(`'${this.reaction}' cannot be empty`);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
this.service.unreact(id, author, reaction).then(count => {
|
|
251
|
+
return res.status(200).json(count).end();
|
|
252
|
+
}).catch(err => handleError(err, res, this.log));
|
|
253
|
+
}
|
|
254
|
+
checkReaction(req: Request, res: Response): void {
|
|
255
|
+
const id = req.params.id;
|
|
256
|
+
const author = req.params.author;
|
|
257
|
+
if (!id || id.length === 0) {
|
|
258
|
+
res.status(400).end(`'${this.id}' cannot be empty`);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (!author || author.length === 0) {
|
|
262
|
+
res.status(400).end(`'${this.author}' cannot be empty`);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
this.service.checkReaction(id, author).then(count => {
|
|
266
|
+
return res.status(200).json(count).end();
|
|
267
|
+
}).catch(err => handleError(err, res, this.log));
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
export const ReactController = ReactionController;
|
|
271
|
+
export const UserReactionController = ReactionController;
|