Skip to content

Commit

Permalink
feat: shooting notice (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmarchois authored May 30, 2021
1 parent 7cd696c commit c760687
Show file tree
Hide file tree
Showing 20 changed files with 80 additions and 28 deletions.
14 changes: 14 additions & 0 deletions api/migrations/1622382189406-ShootingNotice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {MigrationInterface, QueryRunner} from "typeorm";

export class ShootingNotice1622382189406 implements MigrationInterface {
name = 'ShootingNotice1622382189406'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "shooting" ADD "notice" character varying`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "shooting" DROP COLUMN "notice"`);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export class CreateShootingCommand implements ICommand {
public readonly name: string,
public readonly shootingDate: Date,
public readonly closingDate: Date,
public readonly schoolId: string
public readonly schoolId: string,
public readonly notice: string,
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ describe('CreateShootingCommandHandler', () => {
let createdShooting: Shooting;
let handler: CreateShootingCommandHandler;

const product = mock(Product);
const school = mock(School);
const command = new CreateShootingCommand(
'Prise de vue début année',
new Date('2021-04-18'),
new Date('2021-09-01'),
'553e2b3c-eb11-42b1-8f76-903add071ca7',
'Message notice'
);

beforeEach(() => {
Expand Down Expand Up @@ -49,6 +49,7 @@ describe('CreateShootingCommandHandler', () => {
new Date('2021-09-01'),
ShootingStatus.DISABLED,
instance(school),
'Message notice'
)
)
)
Expand All @@ -67,6 +68,7 @@ describe('CreateShootingCommandHandler', () => {
new Date('2021-09-01'),
ShootingStatus.DISABLED,
instance(school),
'Message notice'
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class CreateShootingCommandHandler {
) {}

public async execute(command: CreateShootingCommand): Promise<string> {
const { name, closingDate, schoolId, shootingDate } = command;
const { name, closingDate, schoolId, shootingDate, notice } = command;

const school = await this.schoolRepository.findOneById(schoolId);
if (!school) {
Expand All @@ -29,7 +29,8 @@ export class CreateShootingCommandHandler {
shootingDate,
closingDate,
ShootingStatus.DISABLED,
school
school,
notice
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export class UpdateShootingCommand implements ICommand {
public readonly name: string,
public readonly shootingDate: Date,
public readonly closingDate: Date,
public readonly notice: string,
) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('UpdateShootingCommandHandler', () => {
'Prise de vue début année',
new Date('2021-04-18'),
new Date('2021-09-01'),
'Message notice'
);

beforeEach(() => {
Expand Down Expand Up @@ -47,8 +48,9 @@ describe('UpdateShootingCommandHandler', () => {
verify(updatedShooting.update(
'Prise de vue début année',
deepEqual(new Date('2021-04-18')),
deepEqual(new Date('2021-09-01')))
).once();
deepEqual(new Date('2021-09-01')),
'Message notice'
)).once();
verify(shootingRepository.findOneById('17efcbee-bd2f-410e-9e99-51684b592bad')).once();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ export class UpdateShootingCommandHandler {
) { }

public async execute(command: UpdateShootingCommand): Promise<string> {
const { name, closingDate, shootingDate, id } = command;
const { name, closingDate, shootingDate, notice, id } = command;

const shooting = await this.shootingRepository.findOneById(id);
if (!shooting) {
throw new ShootingNotFoundException();
}

shooting.update(name, shootingDate, closingDate);
shooting.update(name, shootingDate, closingDate, notice);
await this.shootingRepository.save(shooting);

return shooting.getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ describe('GetShootingByIdQueryHandler', () => {
'Prise de vue fin année',
ShootingStatus.DISABLED,
new Date('2021-04-18'),
new Date('2021-09-01')
new Date('2021-09-01'),
'Notice'
);

const shooting = mock(Shooting);
when(shooting.getId()).thenReturn('eb9e1d9b-dce2-48a9-b64f-f0872f3157d2');
when(shooting.getName()).thenReturn('Prise de vue fin année');
when(shooting.getClosingDate()).thenReturn(new Date('2021-09-01'));
when(shooting.getShootingDate()).thenReturn(new Date('2021-04-18'));
when(shooting.getNotice()).thenReturn('Notice');
when(shooting.getStatus()).thenReturn(ShootingStatus.DISABLED);
when(
shootingRepository.findOneById('eb9e1d9b-dce2-48a9-b64f-f0872f3157d2')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export class GetShootingByIdQueryHandler {
shooting.getName(),
shooting.getStatus(),
shooting.getShootingDate(),
shooting.getClosingDate()
shooting.getClosingDate(),
shooting.getNotice()
);
}
}
1 change: 1 addition & 0 deletions api/src/Application/School/View/ShootingView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export class ShootingView {
public readonly status: ShootingStatus,
public readonly shootingDate: Date,
public readonly closingDate: Date,
public readonly notice?: string,
) {}
}
8 changes: 6 additions & 2 deletions api/src/Domain/School/Shooting.entity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ describe('Shooting', () => {
new Date('2021-04-17'),
new Date('2021-09-01'),
ShootingStatus.DISABLED,
instance(school)
instance(school),
'Fin des commandes le 10'
);
expect(shooting.getId()).toBeUndefined();
expect(shooting.getName()).toBe('Prise de vue début année');
expect(shooting.getShootingDate()).toMatchObject(new Date('2021-04-17T00:00:00.000Z'));
expect(shooting.getClosingDate()).toMatchObject(new Date('2021-09-01T00:00:00.000Z'));
expect(shooting.getStatus()).toBe(ShootingStatus.DISABLED);
expect(shooting.getSchool()).toBe(instance(school));
expect(shooting.getNotice()).toBe('Fin des commandes le 10');
});

it('testUpdate', () => {
Expand All @@ -33,7 +35,8 @@ describe('Shooting', () => {
shooting.update(
'Prise de vue fin année',
new Date('2022-04-17'),
new Date('2022-09-01')
new Date('2022-09-01'),
'Message notice'
);


Expand All @@ -43,5 +46,6 @@ describe('Shooting', () => {
expect(shooting.getClosingDate()).toMatchObject(new Date('2022-09-01T00:00:00.000Z'));
expect(shooting.getStatus()).toBe(ShootingStatus.DISABLED);
expect(shooting.getSchool()).toBe(instance(school));
expect(shooting.getNotice()).toBe('Message notice');
});
});
13 changes: 12 additions & 1 deletion api/src/Domain/School/Shooting.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export class Shooting {
@Column({ type: 'date', nullable: false })
private closingDate: Date;

@Column({ type: 'varchar', nullable: true })
private notice: string;

@Column('enum', { enum: ShootingStatus, nullable: false, default: ShootingStatus.DISABLED })
private status: ShootingStatus;

Expand All @@ -31,13 +34,15 @@ export class Shooting {
shootingDate: Date,
closingDate: Date,
status: ShootingStatus,
school: School
school: School,
notice?: string
) {
this.name = name;
this.shootingDate = shootingDate;
this.closingDate = closingDate;
this.status = status;
this.school = school;
this.notice = notice;
}

public getId(): string {
Expand All @@ -56,6 +61,10 @@ export class Shooting {
return this.closingDate;
}

public getNotice(): string {
return this.notice;
}

public getSchool(): School {
return this.school;
}
Expand All @@ -68,9 +77,11 @@ export class Shooting {
name: string,
shootingDate: Date,
closingDate: Date,
notice?: string,
): void {
this.name = name;
this.shootingDate = shootingDate;
this.closingDate = closingDate;
this.notice = notice;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ export class CreateShootingAction {
@Roles(UserRole.PHOTOGRAPHER)
@ApiOperation({ summary: 'Create a shooting' })
public async index(@Param() idDto: IdDTO, @Body() dto: ShootingDTO) {
const { name, shootingDate, closingDate } = dto;
const { name, shootingDate, closingDate, notice } = dto;

try {
const id = await this.commandBus.execute(
new CreateShootingCommand(
name,
new Date(shootingDate),
new Date(closingDate),
idDto.id
idDto.id,
notice
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ export class UpdateShootingAction {
@ApiOperation({ summary: 'Update shooting' })
public async index(@Param() idDto: IdDTO, @Body() dto: ShootingDTO) {
try {
const { name, closingDate, shootingDate } = dto;
const { name, closingDate, shootingDate, notice } = dto;
const id = await this.commandBus.execute(
new UpdateShootingCommand(
idDto.id,
name,
new Date(shootingDate),
new Date(closingDate)
new Date(closingDate),
notice
)
);

Expand Down
8 changes: 6 additions & 2 deletions api/src/Infrastructure/School/DTO/ShootingDTO.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsDateString, IsNotEmpty } from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsDateString, IsNotEmpty, IsOptional } from 'class-validator';
import { DateGreaterOrEqualThan } from 'src/Infrastructure/Common/Validator/DateGreaterOrEqualThan';

export class ShootingDTO {
@ApiProperty()
@IsNotEmpty()
public name: string;

@ApiPropertyOptional()
@IsOptional()
public notice: string;

@ApiProperty()
@IsNotEmpty()
@IsDateString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class ShootingRepository implements IShootingRepository {
'shooting.id',
'shooting.name',
'shooting.status',
'shooting.notice',
'shooting.shootingDate',
'shooting.closingDate'
])
Expand Down
7 changes: 4 additions & 3 deletions client/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,17 @@
},
"form": {
"name": "Nom de la prise de vue",
"closing_date": "Date de la fermeture des commandes",
"shooting_date": "Date de la prise de vue"
"closing_date": "Date de la fermeture des commandes groupées",
"shooting_date": "Date de la prise de vue",
"notice": "Message d'information qui sera affiché au client"
},
"status": {
"enabled": "En ligne",
"disabled": "En attente de publication"
},
"list": {
"name": "Prise de vue",
"closing_date": "Fermeture commandes",
"closing_date": "Fermeture commandes groupées",
"shooting_date": "Date",
"status": "Etat",
"class": "Nb classes",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
import { onMount } from 'svelte';
import { get, put } from 'utils/axios';
import Breadcrumb from 'components/Breadcrumb.svelte';
import Form from '../_Form.svelte';
import { errorNormalizer } from 'normalizer/errors';
import ServerErrors from 'components/ServerErrors.svelte';
import H4Title from 'components/H4Title.svelte';
import Form from '../_Form.svelte';
export let id;
export let shootingId;
let loading = false;
let school;
let shooting;
let title = $_('schools.shootings.edit.title');
const title = $_('schools.shootings.edit.title');
let errors = [];
onMount(async () => {
Expand Down Expand Up @@ -70,5 +70,6 @@
name={shooting.name}
closingDate={shooting.closingDate}
shootingDate={shooting.shootingDate}
notice={shooting.notice}
{loading} />
{/if}
8 changes: 7 additions & 1 deletion client/src/routes/admin/schools/[id]/shootings/_Form.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
export let shootingDate = '';
export let closingDate = '';
export let name = '';
export let notice = '';
export let loading;
const dispatch = createEventDispatcher();
const submit = () => {
dispatch('save', {
name,
closingDate: new Date(closingDate),
shootingDate: new Date(shootingDate)
shootingDate: new Date(shootingDate),
notice
});
};
</script>
Expand All @@ -33,6 +35,10 @@
type={'date'}
label={$_('schools.shootings.form.closing_date')}
bind:value={closingDate} />
<Input
required={false}
label={$_('schools.shootings.form.notice')}
bind:value={notice} />
<Button
value={$_('common.form.save')}
loading={loading}
Expand Down
3 changes: 0 additions & 3 deletions client/src/routes/admin/schools/[id]/shootings/_Table.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script>
import { _ } from 'svelte-i18n';
import { createEventDispatcher } from 'svelte';
import { format } from 'date-fns';
import { fr } from 'date-fns/locale';
import SeeLink from 'components/links/SeeLink.svelte';
Expand All @@ -9,8 +8,6 @@
export let schoolId;
export let items;
const dispatch = createEventDispatcher();
</script>

<table class="w-full whitespace-no-wrap">
Expand Down

0 comments on commit c760687

Please sign in to comment.