2023-04-25 15:49:47 +00:00
|
|
|
import { Injectable } from '@nestjs/common';
|
2023-05-05 06:56:25 +00:00
|
|
|
import { MatcherRepository } from '../../../database/domain/matcher-repository';
|
2023-04-25 15:49:47 +00:00
|
|
|
import { Ad } from '../../domain/entities/ad';
|
2023-05-05 06:56:25 +00:00
|
|
|
import { DatabaseException } from '../../../database/exceptions/database.exception';
|
2023-04-25 15:49:47 +00:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class AdRepository extends MatcherRepository<Ad> {
|
|
|
|
protected _model = 'ad';
|
|
|
|
|
|
|
|
async createAd(ad: Partial<Ad>): Promise<Ad> {
|
|
|
|
try {
|
|
|
|
const affectedRowNumber = await this.createWithFields(
|
|
|
|
this.createFields(ad),
|
|
|
|
);
|
|
|
|
if (affectedRowNumber == 1) {
|
|
|
|
return this.findOneByUuid(ad.uuid);
|
|
|
|
}
|
|
|
|
throw new DatabaseException();
|
|
|
|
} catch (e) {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private createFields(ad: Partial<Ad>): Partial<AdFields> {
|
|
|
|
return {
|
|
|
|
uuid: `'${ad.uuid}'`,
|
|
|
|
driver: ad.driver ? 'true' : 'false',
|
|
|
|
passenger: ad.passenger ? 'true' : 'false',
|
|
|
|
frequency: ad.frequency,
|
|
|
|
fromDate: `'${ad.fromDate}'`,
|
|
|
|
toDate: `'${ad.toDate}'`,
|
|
|
|
monTime: `'${ad.monTime}'`,
|
|
|
|
tueTime: `'${ad.tueTime}'`,
|
|
|
|
wedTime: `'${ad.wedTime}'`,
|
|
|
|
thuTime: `'${ad.thuTime}'`,
|
|
|
|
friTime: `'${ad.friTime}'`,
|
|
|
|
satTime: `'${ad.satTime}'`,
|
|
|
|
sunTime: `'${ad.sunTime}'`,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type AdFields = {
|
|
|
|
uuid: string;
|
|
|
|
driver: string;
|
|
|
|
passenger: string;
|
|
|
|
frequency: number;
|
|
|
|
fromDate: string;
|
|
|
|
toDate: string;
|
|
|
|
monTime: string;
|
|
|
|
tueTime: string;
|
|
|
|
wedTime: string;
|
|
|
|
thuTime: string;
|
|
|
|
friTime: string;
|
|
|
|
satTime: string;
|
|
|
|
sunTime: string;
|
|
|
|
monMargin: number;
|
|
|
|
tueMargin: number;
|
|
|
|
wedMargin: number;
|
|
|
|
thuMargin: number;
|
|
|
|
friMargin: number;
|
|
|
|
satMargin: number;
|
|
|
|
sunMargin: number;
|
|
|
|
driverDuration: number;
|
|
|
|
driverDistance: number;
|
|
|
|
passengerDuration: number;
|
|
|
|
passengerDistance: number;
|
|
|
|
originType: number;
|
|
|
|
destinationType: number;
|
|
|
|
waypoints: string;
|
|
|
|
direction: string;
|
|
|
|
fwdAzimuth: number;
|
|
|
|
backAzimuth: number;
|
|
|
|
seatsDriver: number;
|
|
|
|
seatsPassenger: number;
|
|
|
|
seatsUsed: number;
|
|
|
|
createdAt: string;
|
|
|
|
updatedAt: string;
|
|
|
|
};
|