Skip to content

Commit

Permalink
shortening api added
Browse files Browse the repository at this point in the history
  • Loading branch information
diced committed May 28, 2020
1 parent db02b1d commit 4fe9370
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/controllers/APIController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class APIController {
@Get('images')
@Middleware(cookiesForAPI)
private async allImages(req: Request, res: Response) {
const all = await this.orm.repos.image.find({ order: { id: 'ASC' } });
const all = await this.orm.repos.image.find({ where: { user: req.session.user.id }, order: { id: 'ASC' } });
return res.status(200).json(all);
}

Expand Down Expand Up @@ -195,6 +195,20 @@ export class APIController {
else return res.status(200).json({page: paged[Number(req.query.page)]});
}

@Get('shortens')
@Middleware(cookiesForAPI)
private async allShortens(req: Request, res: Response) {
const all = await this.orm.repos.shorten.find({ where: { user: req.session.user.id }, order: { id: 'ASC' } });
return res.status(200).json(all);
}

@Get('shortens/:id')
@Middleware(cookiesForAPI)
private async getShorten(req: Request, res: Response) {
const all = await this.orm.repos.shorten.find({ where: { user: req.session.user.id, id: Number(req.params.id) }, order: { id: 'ASC' } });
return res.status(200).json(all);
}

public set(orm: ORMHandler) {
this.orm = orm;
return this;
Expand Down

0 comments on commit 4fe9370

Please sign in to comment.