Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class AutoMigration1755523274895 implements MigrationInterface {
UPDATE user_usager
SET "passwordType" = 'RANDOM'
WHERE "isTemporaryPassword" = true
AND "createdAt" >= $1
AND "createdAt" < $1
`,
[cutoffDate]
);
Expand All @@ -45,7 +45,7 @@ export class AutoMigration1755523274895 implements MigrationInterface {
UPDATE user_usager
SET "passwordType" = 'BIRTH_DATE'
WHERE "isTemporaryPassword" = true
AND "createdAt" < $1
AND "createdAt" >= $1
`,
[cutoffDate]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
expectedResponseStatusBuilder,
} from "../../_tests";
import { AppTestContext, AppTestHttpClient } from "../../util/test";
import { PageOptions } from "@domifa/common";

////////////////// IMPORTANT //////////////////
//
Expand All @@ -19,8 +20,9 @@ export const SmsControllerSecurityTests: AppTestHttpClientSecurityTestDef[] = [
label: `${CONTROLLER}.getUsagerSms`,
query: async (context: AppTestContext) => {
return {
response: await AppTestHttpClient.get(`/sms/usager/4444444`, {
response: await AppTestHttpClient.post(`/sms/usager/4444444`, {
context,
body: new PageOptions(),
}),
expectedStatus: expectedResponseStatusBuilder.allowStructureOnly(
context.user,
Expand Down
39 changes: 25 additions & 14 deletions packages/backend/src/modules/sms/sms.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Usager } from "@domifa/common";
import { Controller, UseGuards, Get } from "@nestjs/common";
import { Controller, UseGuards, Post, Body } from "@nestjs/common";
import { AuthGuard } from "@nestjs/passport";
import { ApiTags, ApiBearerAuth } from "@nestjs/swagger";
import { USER_STRUCTURE_ROLE_ALL } from "../../_common/model";
Expand All @@ -10,6 +10,8 @@ import {
} from "../../auth/decorators";
import { AppUserGuard, UsagerAccessGuard } from "../../auth/guards";
import { messageSmsRepository } from "../../database";
import { PageMetaDto, PageOptionsDto, PageResultsDto } from "../../usagers/dto";
import { ObjectLiteral } from "typeorm";

@Controller("sms")
@UseGuards(AuthGuard("jwt"), AppUserGuard)
Expand All @@ -19,18 +21,27 @@ import { messageSmsRepository } from "../../database";
export class SmsController {
@ApiBearerAuth()
@UseGuards(UsagerAccessGuard)
@Get("usager/:usagerRef")
public async getUsagerSms(@CurrentUsager() currentUsager: Usager) {
return await messageSmsRepository.find({
where: {
usagerRef: currentUsager.ref,
structureId: currentUsager.structureId,
},
order: {
createdAt: "DESC",
},
skip: 0,
take: 50,
});
@Post("usager/:usagerRef")
public async getUsagerSms(
@CurrentUsager() currentUsager: Usager,
@Body() pageOptionsDto: PageOptionsDto
) {
const queryBuilder = messageSmsRepository.createQueryBuilder("message_sms");

const whereConditions: ObjectLiteral = {
structureId: currentUsager.structureId,
usagerRef: currentUsager.ref,
};

queryBuilder
.where(whereConditions)
.orderBy("id", pageOptionsDto.order)
.skip((pageOptionsDto.page - 1) * pageOptionsDto.take)
.take(pageOptionsDto.take);

const itemCount = await queryBuilder.getCount();
const { entities } = await queryBuilder.getRawAndEntities();
const pageMetaDto = new PageMetaDto({ itemCount, pageOptionsDto });
return new PageResultsDto(entities, pageMetaDto);
}
}
13 changes: 13 additions & 0 deletions packages/common/src/pagination/PageOptions.class.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Order } from "./PageOrder.enum";

export class PageOptions {
public order: Order;
public page: number;
public take: number;

constructor(options?: Partial<PageOptions>) {
this.order = options?.order ?? Order.DESC;
this.page = options?.page ?? 1;
this.take = options?.take ?? 5;
}
}
7 changes: 0 additions & 7 deletions packages/common/src/pagination/PageOptions.interface.ts

This file was deleted.

18 changes: 18 additions & 0 deletions packages/common/src/pagination/PageResults.class.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { type PageMeta } from "./PageMeta.interface";

export class PageResults<T> {
public data: T[];
public meta: PageMeta;

constructor(results?: PageResults<T>) {
this.data = results?.data ?? [];
this.meta = results?.meta ?? {
page: 0,
take: 0,
itemCount: 0,
pageCount: 0,
hasPreviousPage: false,
hasNextPage: false,
};
}
}
6 changes: 0 additions & 6 deletions packages/common/src/pagination/PageResults.interface.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/common/src/pagination/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @index('./*', f => `export * from '${f.path}'`)
export * from "./PageMeta.interface";
export * from "./PageOptions.interface";
export * from "./PageOptions.class";
export * from "./PageOrder.enum";
export * from "./PageResults.interface";
export * from "./PageResults.class";
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Component, OnInit, TemplateRef, ViewChild } from "@angular/core";
import { NgbModal, NgbModalRef } from "@ng-bootstrap/ng-bootstrap";
import {
Order,
PageOptions,
PageResults,
UsagersCountByStatus,
Expand All @@ -23,24 +22,9 @@ import saveAs from "file-saver";
export class ManageUserUsagerComponent implements OnInit {
@ViewChild("activateAllAccountsModal", { static: true })
public activateAllAccountsModal!: TemplateRef<NgbModalRef>;
public params = new PageOptions({ take: 50 });

public params: PageOptions = {
order: Order.DESC,
page: 1,
take: 50,
};

public searchResults: PageResults<UserUsagerWithUsagerInfo> = {
data: [],
meta: {
page: 0,
take: 0,
itemCount: 0,
pageCount: 0,
hasPreviousPage: false,
hasNextPage: false,
},
};
public searchResults = new PageResults<UserUsagerWithUsagerInfo>();
public loading = false;
public activatingAccounts = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { UsagerLight } from "../../../../../_common/model";
import {
PageOptions,
PageResults,
Order,
UsagerNote,
UserStructure,
} from "@domifa/common";
Expand All @@ -23,7 +22,7 @@ export class BaseUsagerNotesComponent implements OnInit, OnDestroy {
@Input() public me!: UserStructure;
@Input() public usager!: UsagerFormModel;

public params!: PageOptions;
public params = new PageOptions();

public loading: boolean;
public notes: UsagerNote[];
Expand All @@ -41,11 +40,7 @@ export class BaseUsagerNotesComponent implements OnInit, OnDestroy {
) {
this.loading = false;
this.notes = [];
this.params = {
order: Order.DESC,
page: 1,
take: 5,
};

this.currentUserSubject$ = this.authService.currentUserSubject;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
UserStructure,
Interaction,
PageOptions,
Order,
PageResults,
} from "@domifa/common";

Expand All @@ -40,25 +39,9 @@ export class ProfilHistoriqueCourriersComponent implements OnInit, OnDestroy {
public deleteInteractionModal!: TemplateRef<NgbModalRef>;

public loading: boolean;
public params = new PageOptions({ take: 50 });

public params: PageOptions = {
order: Order.DESC,
page: 1,
take: 50,
};

public searchResults: PageResults<Interaction> = {
data: [],
meta: {
page: 0,
take: 0,
itemCount: 0,
pageCount: 0,
hasPreviousPage: false,
hasNextPage: false,
},
};

public searchResults = new PageResults<Interaction>();
constructor(
private readonly toastService: CustomToastService,
private readonly interactionService: InteractionService,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Component, Input, OnDestroy, OnInit } from "@angular/core";
import {
Order,
PageOptions,
PageResults,
UserStructure,
Expand Down Expand Up @@ -29,23 +28,11 @@ export class ProfilHistoriqueLoginPortailComponent

public loading: boolean;

public params: PageOptions = {
order: Order.DESC,
page: 1,
public params = new PageOptions({
take: 10,
};
});

public searchResults: PageResults<UserUsagerLogin> = {
data: [],
meta: {
page: 0,
take: 0,
itemCount: 0,
pageCount: 0,
hasPreviousPage: false,
hasNextPage: false,
},
};
public searchResults = new PageResults<UserUsagerLogin>();

constructor(private readonly interactionService: InteractionService) {
this.loading = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h3>Historique des envois de SMS</h3>
</li>
</ul>

<div class="table-responsive" *ngIf="messagesList?.length > 0">
<div class="table-responsive" *ngIf="searchResults.data?.length">
<table class="table-history table">
<caption class="visually-hidden">
Historique des SMS envoyés
Expand All @@ -27,7 +27,7 @@ <h3>Historique des envois de SMS</h3>
</tr>
</thead>
<tbody>
<tr *ngFor="let sms of messagesList">
<tr *ngFor="let sms of searchResults.data">
<td>
{{
(sms.sendDate ? sms.sendDate : sms.scheduledDate)
Expand All @@ -42,7 +42,41 @@ <h3>Historique des envois de SMS</h3>
</tbody>
</table>
</div>
<div
class="justify-content-center d-flex p-3 d-print-none"
*ngIf="
searchResults.data.length > 0 && searchResults.meta.itemCount >= params.take
"
>
<div
class="results-selector justify-content-start align-items-center d-flex me-auto"
>
<select
name="limit"
[(ngModel)]="params.take"
(ngModelChange)="getSms()"
id="limit"
>
<option [ngValue]="10">10</option>
<option [ngValue]="50">50</option>
<option [ngValue]="100">100</option>
<option [ngValue]="250">250</option>
<option [ngValue]="500">500</option>
</select>
<label for="limit" class="ms-3 fw-bold">résultats par page </label>
</div>

<div *ngIf="messagesList?.length === 0" class="alert alert-info">
<ngb-pagination
[collectionSize]="searchResults.meta.itemCount"
[(page)]="params.page"
[boundaryLinks]="true"
[rotate]="true"
[maxSize]="5"
[pageSize]="params.take"
(pageChange)="getSms()"
></ngb-pagination>
</div>

<div *ngIf="searchResults?.data?.length === 0" class="alert alert-info">
<p>Aucun sms enregistré actuellement</p>
</div>
Loading