-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from ti-broish/violations-filters
Филтри за сигналите в преброителния център
- Loading branch information
Showing
15 changed files
with
211 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/migrations/1624337501383-AddTownsCountryMunicipalityIndices.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class AddTownsCountryMunicipalityIndices1624337501383 | ||
implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
create index "towns_country_id_key" on "towns" ("country_id"); | ||
create index "towns_municipality_id_key" on "towns" ("country_id"); | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
drop index "towns_municipality_id_key"; | ||
drop index "towns_country_id_key"; | ||
`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { | ||
registerDecorator, | ||
ValidationArguments, | ||
ValidationOptions, | ||
ValidatorConstraint, | ||
ValidatorConstraintInterface, | ||
} from 'class-validator'; | ||
|
||
@ValidatorConstraint({ async: true }) | ||
@Injectable() | ||
export class IsULIDConstraint implements ValidatorConstraintInterface { | ||
async validate(id?: string): Promise<boolean> { | ||
return typeof id === 'string' && /[A-Z0-9]{26}/.test(id); | ||
} | ||
|
||
defaultMessage?(context: ValidationArguments): string { | ||
console.debug(context.object); | ||
return `${context.property} identifier is not an ULID`; | ||
} | ||
} | ||
|
||
export function IsULID(validationOptions?: ValidationOptions) { | ||
return function (entity: object, propertyName: string) { | ||
registerDecorator({ | ||
target: entity.constructor, | ||
propertyName: propertyName, | ||
options: validationOptions, | ||
constraints: [], | ||
validator: IsULIDConstraint, | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,62 @@ | ||
import { Optional } from '@nestjs/common'; | ||
import { Type } from 'class-transformer'; | ||
import { | ||
IsBooleanString, | ||
IsInt, | ||
IsNumberString, | ||
IsOptional, | ||
Length, | ||
} from 'class-validator'; | ||
import { IsTownExists } from 'src/sections/api/town-exists.constraint'; | ||
import { IsOrganizationExists } from 'src/users/api/organization-exists.constraint'; | ||
import { IsUserExists } from 'src/users/api/user-exists.constraint'; | ||
import { PageDTO } from 'src/utils/page.dto'; | ||
import { IsULID } from 'src/utils/ulid-constraint'; | ||
import { ViolationStatus } from '../entities/violation.entity'; | ||
|
||
export class ViolationsFilters extends PageDTO { | ||
@Optional() | ||
@IsOptional() | ||
@IsULID() | ||
@IsUserExists() | ||
assignee: string; | ||
|
||
@Optional() | ||
@IsOptional() | ||
@Length(1, 9) | ||
section: string; | ||
|
||
@Optional() | ||
@IsOptional() | ||
status: ViolationStatus; | ||
|
||
@Optional() | ||
author: string; | ||
@IsOptional() | ||
@IsNumberString() | ||
@Length(2, 2) | ||
electionRegion: string; | ||
|
||
@Optional() | ||
@IsOptional() | ||
@IsNumberString() | ||
@Length(2, 2) | ||
municipality: string; | ||
|
||
@IsOptional() | ||
@IsNumberString() | ||
@Length(2, 2) | ||
country: string; | ||
|
||
@IsOptional() | ||
@IsTownExists() | ||
town: number; | ||
|
||
@Optional() | ||
@IsOptional() | ||
@IsNumberString() | ||
@Length(2, 2) | ||
cityRegion: string; | ||
|
||
@IsOptional() | ||
@IsInt() | ||
@Type(() => Number) | ||
@IsOrganizationExists() | ||
organization: number; | ||
|
||
@IsOptional() | ||
@IsBooleanString() | ||
published: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.