Skip to content
Merged
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
13 changes: 13 additions & 0 deletions src/migrations/1713520000000-AddTypeToViolations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { MigrationInterface, QueryRunner } from 'typeorm'

export class AddTypeToViolations1713520000000 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "violations" ADD "type" varchar NOT NULL DEFAULT 'standard'`,
)
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "violations" DROP COLUMN "type"`)
}
}
12 changes: 11 additions & 1 deletion src/violations/api/violation.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
IsArray,
IsBoolean,
IsEmail,
IsEnum,
IsNotEmpty,
IsOptional,
IsPhoneNumber,
Expand All @@ -21,7 +22,11 @@ import {
} from 'class-validator'
import { SectionDto } from '../../sections/api/section.dto'
import { PictureDto } from '../../pictures/api/picture.dto'
import { Violation, ViolationStatus } from '../entities/violation.entity'
import {
Violation,
ViolationStatus,
ViolationType,
} from '../entities/violation.entity'
import { TownDto } from '../../sections/api/town.dto'
import { UserDto } from 'src/users/api/user.dto'
import { ViolationUpdateDto } from './violation-update.dto'
Expand All @@ -42,6 +47,11 @@ export class ViolationDto {
@Expose({ groups: ['read', ViolationDto.FEED] })
id: string

@Expose({ groups: ['read', 'create', ViolationDto.FEED] })
@IsOptional({ groups: ['create'] })
@IsEnum(ViolationType, { groups: ['create'] })
type: ViolationType

@Expose({ groups: ['read', 'create', ViolationDto.FEED] })
@Type(() => SectionDto)
@ValidateIf((violationDto: ViolationDto) => violationDto.town !== undefined)
Expand Down
7 changes: 6 additions & 1 deletion src/violations/api/violations-filters.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from 'class-validator'
import { IsTownExists } from 'src/sections/api/town-exists.constraint'
import { PageDTO } from 'src/utils/page.dto'
import { ViolationStatus } from '../entities/violation.entity'
import { ViolationStatus, ViolationType } from '../entities/violation.entity'

export class ViolationsFilters extends PageDTO {
@IsOptional()
Expand Down Expand Up @@ -54,4 +54,9 @@ export class ViolationsFilters extends PageDTO {
@IsOptional()
@IsBooleanString()
published: boolean

@IsOptional()
@IsString()
@IsEnum(ViolationType)
type: ViolationType
}
8 changes: 8 additions & 0 deletions src/violations/entities/violation.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,21 @@ export enum ViolationStatus {
REJECTED = 'rejected',
}

export enum ViolationType {
STANDARD = 'standard',
VIDEO = 'video',
}

@Entity('violations', { orderBy: { id: 'DESC' } })
export class Violation {
@PrimaryColumn('char', {
length: 26,
})
id: string = ulid()

@Column({ type: 'varchar', default: ViolationType.STANDARD })
type: ViolationType

@Column({ type: 'text' })
description: string

Expand Down
8 changes: 8 additions & 0 deletions src/violations/entities/violations.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ export class ViolationsRepository {
})
}

if (filters.type) {
qb.andWhere('violation.type = :type', { type: filters.type })
}

return qb
}

Expand Down Expand Up @@ -302,6 +306,10 @@ export class ViolationsRepository {
})
}

if (filters.type) {
qb.andWhere('violation.type = :type', { type: filters.type })
}

return qb.getCount()
}

Expand Down
Loading