Skip to content

Commit

Permalink
th-248: Remove Non-nullable From driver_license_file (BinaryStudioAca…
Browse files Browse the repository at this point in the history
…demy#389)

* th-248: - remove non-nullable from driver_license_file_id in driver_details

* th-248: * fix the bug when the driversService.findByUserId returns null for dirver with unverified status

* th-248: - remove redundant null
  • Loading branch information
Some14u committed Sep 28, 2023
1 parent 791402a commit 75efea8
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CREATE TABLE IF NOT EXISTS

--> statement-breakpoint
ALTER TABLE "driver_details"
ADD COLUMN "driver_license_file_id" integer NOT NULL;
ADD COLUMN "driver_license_file_id" integer;

--> statement-breakpoint
DO $$ BEGIN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@
"driver_license_file_id": {
"name": "driver_license_file_id",
"type": "integer",
"primaryKey": false,
"notNull": true
"primaryKey": false
},
"user_id": {
"name": "user_id",
Expand Down
6 changes: 3 additions & 3 deletions backend/src/libs/packages/database/schema/tables-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ const files = pgTable('files', {
const drivers = pgTable('driver_details', {
id: serial('id').primaryKey(),
driverLicenseNumber: varchar('driver_license_number').unique().notNull(),
driverLicenseFileId: integer('driver_license_file_id')
.references(() => files.id)
.notNull(),
driverLicenseFileId: integer('driver_license_file_id').references(
() => files.id,
),
userId: integer('user_id')
.notNull()
.references(() => users.id),
Expand Down
22 changes: 14 additions & 8 deletions backend/src/packages/business/business.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,11 @@ class BusinessService implements IService {
});
}

await this.fileVerificationStatusService.deleteByFileId(
driverToUpdate.driverLicenseFileId,
);
if (driverToUpdate.driverLicenseFileId) {
await this.fileVerificationStatusService.deleteByFileId(
driverToUpdate.driverLicenseFileId,
);
}

const newLicenseFile = await this.fileService.create(payload.files[0]);

Expand All @@ -290,7 +292,9 @@ class BusinessService implements IService {
name: FileVerificationName.DRIVER_LICENSE_SCAN,
});

await this.fileService.delete(driverToUpdate.driverLicenseFileId);
if (driverToUpdate.driverLicenseFileId) {
await this.fileService.delete(driverToUpdate.driverLicenseFileId);
}

return {
...updatedDriver,
Expand Down Expand Up @@ -347,10 +351,12 @@ class BusinessService implements IService {

const result = await this.driverService.delete(driverId);

await this.fileVerificationStatusService.deleteByFileId(
driverToDelete.driverLicenseFileId,
);
await this.fileService.delete(driverToDelete.driverLicenseFileId);
if (driverToDelete.driverLicenseFileId) {
await this.fileVerificationStatusService.deleteByFileId(
driverToDelete.driverLicenseFileId,
);
await this.fileService.delete(driverToDelete.driverLicenseFileId);
}

return result;
}
Expand Down
4 changes: 2 additions & 2 deletions backend/src/packages/drivers/driver.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class DriverRepository implements IRepository {
...SELECT_FILTER_JOIN_USER,
})
.from(this.driverSchema)
.innerJoin(
.leftJoin(
schema.fileVerificationStatus,
eq(
this.driverSchema.driverLicenseFileId,
Expand Down Expand Up @@ -91,7 +91,7 @@ class DriverRepository implements IRepository {
...SELECT_FILTER_JOIN_USER,
})
.from(this.driverSchema)
.innerJoin(
.leftJoin(
schema.fileVerificationStatus,
eq(
this.driverSchema.driverLicenseFileId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type DriverEntityT = {
businessId: BusinessEntityT['id'];
createdAt: string;
avatarId: FileEntityT['id'] | null;
driverLicenseFileId: FileEntityT['id'];
driverLicenseFileId: FileEntityT['id'] | null;
verificationStatus: Omit<FileVerificationStatusEntityT, 'fileId'> | null;
};

Expand Down

0 comments on commit 75efea8

Please sign in to comment.