Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions back/src/controllers/abstract.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IRequest, Paging } from '../models';
import { IRequest, Paging, ISortParams } from '../models';

const IGNORED_FILTERS = new Set<string>(['fields', 'paging']);

Expand All @@ -11,7 +11,7 @@ export abstract class AController {
keys.filter(key => !IGNORED_FILTERS.has(key))
.forEach(key => {
// Like operator?
const likeRegex = /like,([a-zA-Z0-9]+)/mg.exec(query[key]);
const likeRegex = /like,([A-Za-zÀ-ÖØ-öø-ÿœ]+)/mg.exec(query[key]);
if (likeRegex != null) {
result[key] = {
$regex: likeRegex[1],
Expand All @@ -29,7 +29,7 @@ export abstract class AController {
return (request?.query?.fields || '').split(',');
}

protected getPaging(request: IRequest): Paging {
return Paging.parse(request?.query?.paging);
protected getPaging(request: IRequest, sortParams?: ISortParams): Paging {
return Paging.parse(request?.query?.paging, sortParams);
}
}
9 changes: 8 additions & 1 deletion back/src/controllers/recipes.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class RecipesController extends AController {
RecipeSchema.find(
this.getFilters(request),
this.getFields(request),
this.getPaging(request),
this.getPaging(request, { key: "publicationDate", direction: -1 }),
(error: Error, recipes: Document[]) => {
if (error != null) {
response.send(error);
Expand Down Expand Up @@ -77,6 +77,13 @@ export class RecipesController extends AController {
}

public update(request: Request, response: Response): void {
let loginController = new LoginController()
if (!loginController.isLogged(request)) {
response.status(403);
response.send('Vous devez être identifié en tant qu\'admin');
return;
}

delete request.body._id;
const pictureRegex = new RegExp('^data:image', 'i');
const picture = request.body.mainPicture;
Expand Down
2 changes: 1 addition & 1 deletion back/src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { IEnvironment } from "../models/environment";

export const PROD_ENV: IEnvironment = {
isProduction: true,
frontendUrl: 'https://curry-chronicles.github.io'
frontendUrl: 'https://curry-chronicles.fr'
};
13 changes: 10 additions & 3 deletions back/src/models/request.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,25 @@ export interface IQuery {
paging?: string;
}

export interface ISortParams {
key: string,
direction: number
}

export class Paging {
constructor(
public skip: number,
public limit: number
public limit: number,
public sort?: any
) { }

public static parse(rawPaging: string): Paging {
public static parse(rawPaging: string, sortParams?: ISortParams): Paging {
const splitted = (rawPaging || '').split(',').map(value => parseInt(value));
if (splitted == null || splitted.length == null) {
return null;
}
return new Paging(splitted[0], splitted[1]);
const sort = sortParams == null ? {} : {[sortParams.key]: sortParams.direction};
return new Paging(splitted[0], splitted[1], sort);
}
}

Expand Down
Loading