mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 08:34:55 +00:00
Compare commits
12 Commits
4f778f7904
...
ZOD-349-we
| Author | SHA1 | Date | |
|---|---|---|---|
| 05a6ad2d84 | |||
| bbeece9e03 | |||
| 596562f6dc | |||
| 10de8f69c9 | |||
| 8a6b1cc900 | |||
| d16ae66252 | |||
| e966f95463 | |||
| 2714255dd1 | |||
| 39a0b131b8 | |||
| 7bfc14f0d9 | |||
| f3282a680b | |||
| d70ab09960 |
@ -163,8 +163,8 @@ export class CardService {
|
|||||||
return finalAmount.toNumber();
|
return finalAmount.toNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
getWeeklySummary(juniorId: string) {
|
getWeeklySummary(juniorId: string, startDate?: Date, endDate?: Date) {
|
||||||
return this.transactionService.getWeeklySummary(juniorId);
|
return this.transactionService.getWeeklySummary(juniorId, startDate, endDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
fundIban(iban: string, amount: number) {
|
fundIban(iban: string, amount: number) {
|
||||||
|
|||||||
@ -84,15 +84,28 @@ export class TransactionService {
|
|||||||
return existingTransaction;
|
return existingTransaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getWeeklySummary(juniorId: string) {
|
async getWeeklySummary(juniorId: string, startDate?: Date, endDate?: Date) {
|
||||||
const startOfWeek = moment().startOf('week').toDate();
|
let startOfWeek: Date;
|
||||||
const endOfWeek = moment().endOf('week').toDate();
|
let endOfWeek: Date;
|
||||||
|
|
||||||
|
if (startDate && endDate) {
|
||||||
|
startOfWeek = startDate;
|
||||||
|
endOfWeek = endDate;
|
||||||
|
} else {
|
||||||
|
const now = moment();
|
||||||
|
const dayOfWeek = now.day();
|
||||||
|
|
||||||
|
startOfWeek = moment().subtract(dayOfWeek, 'days').startOf('day').toDate();
|
||||||
|
|
||||||
|
endOfWeek = moment().add(6 - dayOfWeek, 'days').endOf('day').toDate();
|
||||||
|
}
|
||||||
|
|
||||||
const transactions = await this.transactionRepository.getTransactionsForCardWithinDateRange(
|
const transactions = await this.transactionRepository.getTransactionsForCardWithinDateRange(
|
||||||
juniorId,
|
juniorId,
|
||||||
startOfWeek,
|
startOfWeek,
|
||||||
endOfWeek,
|
endOfWeek,
|
||||||
);
|
);
|
||||||
|
|
||||||
const summary = {
|
const summary = {
|
||||||
startOfWeek: startOfWeek,
|
startOfWeek: startOfWeek,
|
||||||
endOfWeek: endOfWeek,
|
endOfWeek: endOfWeek,
|
||||||
|
|||||||
@ -0,0 +1,15 @@
|
|||||||
|
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||||
|
|
||||||
|
export class AddUniqueConstraintToUserEmail1761032305682 implements MigrationInterface {
|
||||||
|
name = 'AddUniqueConstraintToUserEmail1761032305682'
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
|
||||||
|
await queryRunner.query(`ALTER TABLE "users" ADD CONSTRAINT "UQ_97672ac88f789774dd47f7c8be3" UNIQUE ("email")`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`ALTER TABLE "users" DROP CONSTRAINT "UQ_97672ac88f789774dd47f7c8be3"`);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -4,4 +4,5 @@ export * from './1754915164810-seed-default-avatar';
|
|||||||
export * from './1757349525708-create-money-requests-table';
|
export * from './1757349525708-create-money-requests-table';
|
||||||
export * from './1757433339849-add-reservation-amount-to-account-entity';
|
export * from './1757433339849-add-reservation-amount-to-account-entity';
|
||||||
export * from './1757915357218-add-deleted-at-column-to-junior';
|
export * from './1757915357218-add-deleted-at-column-to-junior';
|
||||||
export * from './1760869651296-AddMerchantInfoToTransactions';
|
export * from './1760869651296-AddMerchantInfoToTransactions';
|
||||||
|
export * from './1761032305682-AddUniqueConstraintToUserEmail';
|
||||||
@ -151,11 +151,17 @@ export class JuniorController {
|
|||||||
@UseGuards(RolesGuard)
|
@UseGuards(RolesGuard)
|
||||||
@AllowedRoles(Roles.GUARDIAN)
|
@AllowedRoles(Roles.GUARDIAN)
|
||||||
@ApiDataResponse(WeeklySummaryResponseDto)
|
@ApiDataResponse(WeeklySummaryResponseDto)
|
||||||
|
@ApiQuery({ name: 'startUtc', required: false, type: String, example: '2025-10-20T00:00:00.000Z', description: 'Start date (defaults to start of current week)' })
|
||||||
|
@ApiQuery({ name: 'endUtc', required: false, type: String, example: '2025-10-26T23:59:59.999Z', description: 'End date (defaults to end of current week)' })
|
||||||
async getWeeklySummary(
|
async getWeeklySummary(
|
||||||
@Param('juniorId', CustomParseUUIDPipe) juniorId: string,
|
@Param('juniorId', CustomParseUUIDPipe) juniorId: string,
|
||||||
@AuthenticatedUser() user: IJwtPayload,
|
@AuthenticatedUser() user: IJwtPayload,
|
||||||
|
@Query('startUtc') startUtc?: string,
|
||||||
|
@Query('endUtc') endUtc?: string,
|
||||||
) {
|
) {
|
||||||
const summary = await this.juniorService.getWeeklySummary(juniorId, user.sub);
|
const startDate = startUtc ? new Date(startUtc) : undefined;
|
||||||
|
const endDate = endUtc ? new Date(endUtc) : undefined;
|
||||||
|
const summary = await this.juniorService.getWeeklySummary(juniorId, user.sub, startDate, endDate);
|
||||||
return ResponseFactory.data(summary);
|
return ResponseFactory.data(summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -212,8 +212,8 @@ export class JuniorService {
|
|||||||
this.logger.log(`Junior ${juniorId} deleted successfully`);
|
this.logger.log(`Junior ${juniorId} deleted successfully`);
|
||||||
}
|
}
|
||||||
|
|
||||||
getWeeklySummary(juniorId: string, guardianId: string) {
|
async getWeeklySummary(juniorId: string, guardianId: string, startDate?: Date, endDate?: Date) {
|
||||||
const doesBelong = this.doesJuniorBelongToGuardian(guardianId, juniorId);
|
const doesBelong = await this.doesJuniorBelongToGuardian(guardianId, juniorId);
|
||||||
|
|
||||||
if (!doesBelong) {
|
if (!doesBelong) {
|
||||||
this.logger.error(`Junior ${juniorId} does not belong to guardian ${guardianId}`);
|
this.logger.error(`Junior ${juniorId} does not belong to guardian ${guardianId}`);
|
||||||
@ -221,7 +221,7 @@ export class JuniorService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.logger.log(`Getting weekly summary for junior ${juniorId}`);
|
this.logger.log(`Getting weekly summary for junior ${juniorId}`);
|
||||||
return this.cardService.getWeeklySummary(juniorId);
|
return this.cardService.getWeeklySummary(juniorId, startDate, endDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getJuniorHome(juniorId: string, userId: string, size: number): Promise<JuniorHomeResponseDto> {
|
async getJuniorHome(juniorId: string, userId: string, size: number): Promise<JuniorHomeResponseDto> {
|
||||||
|
|||||||
@ -28,7 +28,7 @@ export class User extends BaseEntity {
|
|||||||
@Column('varchar', { length: 255, name: 'last_name', nullable: false })
|
@Column('varchar', { length: 255, name: 'last_name', nullable: false })
|
||||||
lastName!: string;
|
lastName!: string;
|
||||||
|
|
||||||
@Column('varchar', { length: 255, name: 'email', nullable: true })
|
@Column('varchar', { length: 255, name: 'email', nullable: true, unique: true })
|
||||||
email!: string;
|
email!: string;
|
||||||
|
|
||||||
@Column('varchar', { length: 255, name: 'phone_number', nullable: true })
|
@Column('varchar', { length: 255, name: 'phone_number', nullable: true })
|
||||||
|
|||||||
@ -222,7 +222,7 @@ export class UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async updateUserEmail(userId: string, email: string) {
|
async updateUserEmail(userId: string, email: string) {
|
||||||
const userWithEmail = await this.findUser({ email, isEmailVerified: true });
|
const userWithEmail = await this.findUser({ email });
|
||||||
|
|
||||||
if (userWithEmail) {
|
if (userWithEmail) {
|
||||||
if (userWithEmail.id === userId) {
|
if (userWithEmail.id === userId) {
|
||||||
|
|||||||
Reference in New Issue
Block a user