Skip to content

Commit

Permalink
Migrated:
Browse files Browse the repository at this point in the history
banner-response.ts
base-response.ts
pagination.ts
root-controller.ts
  • Loading branch information
JustSamuel committed Dec 25, 2023
1 parent 0c3e49d commit 3cb5fc0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 28 deletions.
8 changes: 4 additions & 4 deletions src/controller/response/banner-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import BaseResponse from './base-response';
import { PaginationResult } from '../../helpers/pagination';

/**
* @typedef {BaseResponse} BannerResponse
* @typedef {allOf|BaseResponse} BannerResponse
* @property {string} name.required - Name/label of the banner
* @property {string} image - Location of the image
* @property {number} duration.required - How long the banner should be shown (in seconds)
Expand All @@ -38,9 +38,9 @@ export interface BannerResponse extends BaseResponse {
}

/**
* @typedef PaginatedBannerResponse
* @property {PaginationResult.model} _pagination - Pagination metadata
* @property {Array.<BannerResponse>} records - Returned banners
* @typedef {object} PaginatedBannerResponse
* @property {PaginationResult} _pagination - Pagination metadata
* @property {Array<BannerResponse>} records - Returned banners
*/
export interface PaginatedBannerResponse {
_pagination: PaginationResult,
Expand Down
2 changes: 1 addition & 1 deletion src/controller/response/base-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

/**
* @typedef BaseResponse
* @typedef {object} BaseResponse
* @property {integer} id.required - The unique id of the entity.
* @property {string} createdAt - The creation Date of the entity.
* @property {string} updatedAt - The last update Date of the entity.
Expand Down
34 changes: 17 additions & 17 deletions src/controller/root-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { Request, Response } from 'express';
import log4js, { Logger } from 'log4js';
import { getConnection } from 'typeorm';
import BaseController, { BaseControllerOptions } from './base-controller';
import {Request, Response} from 'express';
import log4js, {Logger} from 'log4js';
import {getConnection} from 'typeorm';
import BaseController, {BaseControllerOptions} from './base-controller';
import Policy from './policy';
import { parseRequestPagination } from '../helpers/pagination';
import {parseRequestPagination} from '../helpers/pagination';
import BannerService from '../service/banner-service';

export default class RootController extends BaseController {
Expand Down Expand Up @@ -59,15 +59,15 @@ export default class RootController extends BaseController {
}

/**
* Returns all existing banners
* @route GET /open/banners
* GET /open/banners
* @summary Returns all existing banners
* @operationId getAllOpenBanners
* @group banners - Operations of banner controller
* @tags banners - Operations of banner controller
* @param {integer} take.query - How many banners the endpoint should return
* @param {integer} skip.query - How many banners should be skipped (for pagination)
* @returns {PaginatedBannerResponse.model} 200 - All existing banners
* @returns {string} 400 - Validation error
* @returns {string} 500 - Internal server error
* @return {PaginatedBannerResponse} 200 - All existing banners
* @return {string} 400 - Validation error
* @return {string} 500 - Internal server error
*/
public async returnAllBanners(req: Request, res: Response): Promise<void> {
this.logger.trace('Get all banners by', req.ip);
Expand All @@ -85,20 +85,20 @@ export default class RootController extends BaseController {

// handle request
try {
res.json(await BannerService.getBanners({}, { take, skip }));
res.json(await BannerService.getBanners({}, {take, skip}));
} catch (error) {
this.logger.error('Could not return all banners:', error);
res.status(500).json('Internal server error.');
}
}

/**
* Ping the backend to check whether everything is working correctly
* @route GET /ping
* GET /ping
* @summary Ping the backend to check whether everything is working correctly
* @operationId ping
* @group root - Operations of the root controller
* @returns {string} 200 - Success
* @returns {string} 500 - Internal server error (database error)
* @tags root - Operations of the root controller
* @return {string} 200 - Success
* @return {string} 500 - Internal server error (database error)
*/
public async ping(req: Request, res: Response): Promise<void> {
this.logger.trace('Ping by', req.ip);
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface PaginationParameters {
}

/**
* @typedef PaginationResult
* @typedef {object} PaginationResult
* @property {integer} take.required Number of records queried
* @property {integer} skip.required Number of skipped records
* @property {integer} count.required Total number of resulting records
Expand Down
15 changes: 10 additions & 5 deletions src/start/swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/* eslint-disable no-new */
import {promises as fs} from 'fs';
import { promises as fs } from 'fs';
import * as path from 'path';
import express from 'express';
import swaggerUi from 'express-swaggerize-ui';
import Validator, {SwaggerSpecification} from 'swagger-model-validator';
import Validator, { SwaggerSpecification } from 'swagger-model-validator';
import generateSpecAndMount from 'express-swagger-generator';
import expressJSDocSwagger from 'express-jsdoc-swagger';

Expand Down Expand Up @@ -74,7 +74,12 @@ export default class Swagger {
},
baseDir: 'C:\\Users\\Samuel\\WebstormProjects\\GEWIS\\SudoSOS\\sudosos-backend\\src\\',
// Glob pattern to find your jsdoc files
filesPattern: ['.\\controller\\root-controller.ts'],
filesPattern: [
'.\\controller\\root-controller.ts',
'./controller/response/banner-response.ts',
'./helpers/pagination.ts',
'./controller/response/base-response.ts'
],
swaggerUIPath: '/api-docs',
exposeSwaggerUI: true, // Expose Swagger UI
exposeApiDocs: true, // Expose API Docs JSON
Expand All @@ -88,7 +93,7 @@ export default class Swagger {
void fs.writeFile(
path.join(process.cwd(), 'out/swagger.json'),
JSON.stringify(swaggerObject),
{encoding: 'utf-8'},
{ encoding: 'utf-8' },
);
});
}
Expand Down Expand Up @@ -141,7 +146,7 @@ if (require.main === module) {
// Only execute directly if this is the main execution file.
const app = express();

fs.mkdir('out', {recursive: true})
fs.mkdir('out', { recursive: true })
.then(() => Swagger.generateNewSpecification(app));

// eslint-disable-next-line @typescript-eslint/no-floating-promises
Expand Down

0 comments on commit 3cb5fc0

Please sign in to comment.