express-ext 0.1.32 → 0.1.35

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 CHANGED
@@ -123,7 +123,7 @@ var SavedController = (function () {
123
123
  return;
124
124
  }
125
125
  this.service.load(id).then(function (data) {
126
- res.status(200).json(data).send();
126
+ res.status(200).json(data).end();
127
127
  })
128
128
  .catch(function (err) { return http_1.handleError(err, res, _this.log); });
129
129
  };
@@ -191,3 +191,77 @@ var FollowController = (function () {
191
191
  return FollowController;
192
192
  }());
193
193
  exports.FollowController = FollowController;
194
+ var UserReactionController = (function () {
195
+ function UserReactionController(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
+ UserReactionController.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
+ UserReactionController.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
+ UserReactionController.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 UserReactionController;
264
+ }());
265
+ exports.UserReactionController = UserReactionController;
266
+ exports.ReactController = UserReactionController;
267
+ exports.ReactionController = UserReactionController;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-ext",
3
- "version": "0.1.32",
3
+ "version": "0.1.35",
4
4
  "description": "express-ext",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
package/src/index.ts CHANGED
@@ -132,7 +132,7 @@ export class SavedController<T> {
132
132
  return;
133
133
  }
134
134
  this.service.load(id).then(data => {
135
- res.status(200).json(data).send();
135
+ res.status(200).json(data).end();
136
136
  })
137
137
  .catch(err => handleError(err, res, this.log));
138
138
  }
@@ -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 UserReactionController {
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 = UserReactionController;
271
+ export const ReactionController = UserReactionController;