Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Fix creating flight
Browse files Browse the repository at this point in the history
  • Loading branch information
anduong96 committed Feb 7, 2024
1 parent c494f05 commit c1f8549
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ model Country {
}

model Flight {
id String @id @default(uuid())
id String @id
flightYear Int @db.SmallInt
flightMonth Int @db.SmallInt
flightDate Int @db.SmallInt
Expand Down
5 changes: 2 additions & 3 deletions src/lib/create.id.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import ShortUniqueId from 'short-unique-id';

const uid = new ShortUniqueId({ length: 10 });
export function createID() {
return uid.rnd();
export function createID(length: number = 10) {
return new ShortUniqueId({ length: length }).rnd();
}
9 changes: 4 additions & 5 deletions src/services/flight/populate.flights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export async function populateFlights(params: FlightQueryParam) {
const result = await prisma.$transaction(
data.map(entry => {
Logger.debug(
'Creating flight=%s%s on date=%s-%s-%s',
'Creating id=%s flight=%s%s on date=%s-%s-%s',
entry.id,
entry.airlineIata,
entry.flightNumber,
entry.flightYear,
Expand All @@ -85,10 +86,8 @@ export async function populateFlights(params: FlightQueryParam) {

return prisma.flight.upsert({
create: entry,
select: {
id: true,
},
update: {},
select: { id: true },
update: { updatedAt: moment().toDate() },
where: {
airlineIata_flightNumber_originIata_destinationIata_flightYear_flightMonth_flightDate:
{
Expand Down

0 comments on commit c1f8549

Please sign in to comment.