Skip to content

Commit 6a4f4b9

Browse files
committed
Change create_at and updated_at to TIMESTAMP WITH TIME ZONE.
1 parent e4e9de2 commit 6a4f4b9

File tree

17 files changed

+84
-45
lines changed

17 files changed

+84
-45
lines changed

package-lock.json

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"@nestjs/cli": "^10.0.0",
4444
"@nestjs/schematics": "^10.0.0",
4545
"@nestjs/testing": "^10.0.0",
46+
"@types/bcrypt": "^5.0.2",
4647
"@types/express": "^4.17.17",
4748
"@types/jest": "^29.5.2",
4849
"@types/node": "^20.3.1",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-- ALTER TABLE
2+
ALTER TABLE "users" ALTER COLUMN "created_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("created_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;
3+
ALTER TABLE "users" ALTER COLUMN "updated_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("updated_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;
4+
5+
-- ALTER TABLE
6+
ALTER TABLE "category_supplies" ALTER COLUMN "created_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("created_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;
7+
ALTER TABLE "category_supplies" ALTER COLUMN "updated_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("updated_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;
8+
9+
-- ALTER TABLE
10+
ALTER TABLE "sessions" ALTER COLUMN "created_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("created_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;
11+
ALTER TABLE "sessions" ALTER COLUMN "updated_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("updated_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;
12+
13+
-- ALTER TABLE
14+
ALTER TABLE "shelter_managers" ALTER COLUMN "created_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("created_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;
15+
ALTER TABLE "shelter_managers" ALTER COLUMN "updated_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("updated_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;
16+
17+
-- ALTER TABLE
18+
ALTER TABLE "shelter_supplies" ALTER COLUMN "created_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("created_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;
19+
ALTER TABLE "shelter_supplies" ALTER COLUMN "updated_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("updated_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;
20+
21+
-- ALTER TABLE
22+
ALTER TABLE "shelters" ALTER COLUMN "created_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("created_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;
23+
ALTER TABLE "shelters" ALTER COLUMN "updated_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("updated_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;
24+
25+
-- ALTER TABLE
26+
ALTER TABLE "supplies" ALTER COLUMN "created_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("created_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;
27+
ALTER TABLE "supplies" ALTER COLUMN "updated_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("updated_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP;
28+

prisma/schema.prisma

+16-16
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ model User {
2222
password String
2323
phone String @unique
2424
accessLevel AccessLevel @default(value: User)
25-
createdAt String @map("created_at") @db.VarChar(32)
26-
updatedAt String? @map("updated_at") @db.VarChar(32)
25+
createdAt DateTime @default(value: now()) @map("created_at") @db.Timestamptz()
26+
updatedAt DateTime? @map("updated_at") @db.Timestamptz()
2727
2828
sessions Session[]
2929
shelterManagers ShelterManagers[]
@@ -37,8 +37,8 @@ model Session {
3737
ip String?
3838
userAgent String? @map("user_agent")
3939
active Boolean @default(value: true)
40-
createdAt String @map("created_at") @db.VarChar(32)
41-
updatedAt String? @map("updated_at") @db.VarChar(32)
40+
createdAt DateTime @default(value: now()) @map("created_at") @db.Timestamptz()
41+
updatedAt DateTime? @map("updated_at") @db.Timestamptz()
4242
4343
user User @relation(fields: [userId], references: [id])
4444
@@ -48,8 +48,8 @@ model Session {
4848
model SupplyCategory {
4949
id String @id @default(uuid())
5050
name String @unique
51-
createdAt String @map("created_at") @db.VarChar(32)
52-
updatedAt String? @map("updated_at") @db.VarChar(32)
51+
createdAt DateTime @default(value: now()) @map("created_at") @db.Timestamptz()
52+
updatedAt DateTime? @map("updated_at") @db.Timestamptz()
5353
5454
supplies Supply[]
5555
@@ -61,8 +61,8 @@ model ShelterSupply {
6161
supplyId String @map("supply_id")
6262
priority Int @default(value: 0)
6363
quantity Int?
64-
createdAt String @map("created_at") @db.VarChar(32)
65-
updatedAt String? @map("updated_at") @db.VarChar(32)
64+
createdAt DateTime @default(value: now()) @map("created_at") @db.Timestamptz()
65+
updatedAt DateTime? @map("updated_at") @db.Timestamptz()
6666
6767
shelter Shelter @relation(fields: [shelterId], references: [id])
6868
supply Supply @relation(fields: [supplyId], references: [id])
@@ -75,8 +75,8 @@ model Supply {
7575
id String @id @default(uuid())
7676
supplyCategoryId String @map("supply_category_id")
7777
name String
78-
createdAt String @map("created_at") @db.VarChar(32)
79-
updatedAt String? @map("updated_at") @db.VarChar(32)
78+
createdAt DateTime @default(value: now()) @map("created_at") @db.Timestamptz()
79+
updatedAt DateTime? @map("updated_at") @db.Timestamptz()
8080
8181
supplyCategory SupplyCategory @relation(fields: [supplyCategoryId], references: [id])
8282
shelterSupplies ShelterSupply[]
@@ -97,8 +97,8 @@ model Shelter {
9797
latitude Float?
9898
longitude Float?
9999
verified Boolean @default(value: false)
100-
createdAt String @map("created_at") @db.VarChar(32)
101-
updatedAt String? @map("updated_at") @db.VarChar(32)
100+
createdAt DateTime @default(value: now()) @map("created_at") @db.Timestamptz()
101+
updatedAt DateTime? @map("updated_at") @db.Timestamptz()
102102
103103
shelterManagers ShelterManagers[]
104104
shelterSupplies ShelterSupply[]
@@ -107,10 +107,10 @@ model Shelter {
107107
}
108108

109109
model ShelterManagers {
110-
shelterId String @map("shelter_id")
111-
userId String @map("user_id")
112-
createdAt String @map("created_at") @db.VarChar(32)
113-
updatedAt String? @map("updated_at") @db.VarChar(32)
110+
shelterId String @map("shelter_id")
111+
userId String @map("user_id")
112+
createdAt DateTime @default(value: now()) @map("created_at") @db.Timestamptz()
113+
updatedAt DateTime? @map("updated_at") @db.Timestamptz()
114114
115115
user User @relation(fields: [userId], references: [id])
116116
shelter Shelter @relation(fields: [shelterId], references: [id])

src/sessions/sessions.service.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class SessionsService {
2727
},
2828
data: {
2929
active: false,
30-
updatedAt: new Date().toISOString(),
30+
updatedAt: new Date(),
3131
},
3232
});
3333

@@ -36,7 +36,7 @@ export class SessionsService {
3636
userId: user.id,
3737
ip,
3838
userAgent,
39-
createdAt: new Date().toISOString(),
39+
createdAt: new Date(),
4040
},
4141
});
4242

@@ -73,7 +73,7 @@ export class SessionsService {
7373
userId,
7474
},
7575
data: {
76-
updatedAt: new Date().toISOString(),
76+
updatedAt: new Date(),
7777
active: false,
7878
},
7979
});

src/shelter-managers/shelter-managers.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class ShelterManagersService {
1414
data: {
1515
shelterId,
1616
userId,
17-
createdAt: new Date().toISOString(),
17+
createdAt: new Date(),
1818
},
1919
});
2020
}

src/shelter-managers/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import z from 'zod';
33
const ShelterManagerSchema = z.object({
44
shelterId: z.string(),
55
userId: z.string(),
6-
createdAt: z.string(),
7-
updatedAt: z.string().optional().nullable(),
6+
createdAt: z.date(),
7+
updatedAt: z.date().optional().nullable(),
88
});
99

1010
const CreateShelterManagerSchema = ShelterManagerSchema.pick({

src/shelter-supply/shelter-supply.service.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class ShelterSupplyService {
2626
prioritySum: {
2727
increment: newPriority - oldPriority,
2828
},
29-
updatedAt: new Date().toISOString(),
29+
updatedAt: new Date(),
3030
},
3131
});
3232
}
@@ -41,7 +41,7 @@ export class ShelterSupplyService {
4141
priority,
4242
supplyId,
4343
quantity: priority !== SupplyPriority.UnderControl ? quantity : null,
44-
createdAt: new Date().toISOString(),
44+
createdAt: new Date(),
4545
},
4646
});
4747
}
@@ -74,7 +74,7 @@ export class ShelterSupplyService {
7474
data: {
7575
...data,
7676
quantity: priority !== SupplyPriority.UnderControl ? quantity : null,
77-
updatedAt: new Date().toISOString(),
77+
updatedAt: new Date(),
7878
},
7979
});
8080
}
@@ -91,7 +91,7 @@ export class ShelterSupplyService {
9191
},
9292
data: {
9393
priority: SupplyPriority.UnderControl,
94-
updatedAt: new Date().toISOString(),
94+
updatedAt: new Date(),
9595
},
9696
});
9797
}

src/shelter-supply/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const ShelterSupplySchema = z.object({
1313
z.literal(SupplyPriority.Urgent),
1414
]),
1515
quantity: z.number().gt(0).nullable().optional(),
16-
createdAt: z.string(),
17-
updatedAt: z.string().nullable().optional(),
16+
createdAt: z.date(),
17+
updatedAt: z.date().nullable().optional(),
1818
});
1919

2020
const CreateShelterSupplySchema = ShelterSupplySchema.pick({

src/shelter/shelter.service.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class ShelterService {
2929
await this.prismaService.shelter.create({
3030
data: {
3131
...payload,
32-
createdAt: new Date().toISOString(),
32+
createdAt: new Date(),
3333
},
3434
});
3535
}
@@ -42,7 +42,7 @@ export class ShelterService {
4242
},
4343
data: {
4444
...payload,
45-
updatedAt: new Date().toISOString(),
45+
updatedAt: new Date(),
4646
},
4747
});
4848
}
@@ -55,7 +55,7 @@ export class ShelterService {
5555
},
5656
data: {
5757
...payload,
58-
updatedAt: new Date().toISOString(),
58+
updatedAt: new Date(),
5959
},
6060
});
6161
}

src/shelter/types/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ const ShelterSchema = z.object({
1919
capacity: z.number().min(0).nullable().optional(),
2020
contact: z.string().nullable().optional(),
2121
verified: z.boolean(),
22-
createdAt: z.string(),
23-
updatedAt: z.string().nullable().optional(),
22+
createdAt: z.date(),
23+
updatedAt: z.date().nullable().optional(),
2424
});
2525

2626
const CreateShelterSchema = ShelterSchema.omit({

src/supply-categories/supply-categories.service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class SupplyCategoriesService {
1616
await this.prismaService.supplyCategory.create({
1717
data: {
1818
...payload,
19-
createdAt: new Date().toISOString(),
19+
createdAt: new Date(),
2020
},
2121
});
2222
}
@@ -29,7 +29,7 @@ export class SupplyCategoriesService {
2929
},
3030
data: {
3131
...payload,
32-
updatedAt: new Date().toISOString(),
32+
updatedAt: new Date(),
3333
},
3434
});
3535
}

src/supply-categories/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export enum SupplyStatus {
1111
const SupplyCategorySchema = z.object({
1212
id: z.string(),
1313
name: z.string().transform(capitalize),
14-
createdAt: z.string(),
15-
updatedAt: z.string().nullable().optional(),
14+
createdAt: z.date(),
15+
updatedAt: z.date().nullable().optional(),
1616
});
1717

1818
const CreateSupplyCategorySchema = SupplyCategorySchema.pick({

src/supply/supply.service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class SupplyService {
1313
return await this.prismaService.supply.create({
1414
data: {
1515
...payload,
16-
createdAt: new Date().toISOString(),
16+
createdAt: new Date(),
1717
},
1818
});
1919
}
@@ -26,7 +26,7 @@ export class SupplyService {
2626
},
2727
data: {
2828
...payload,
29-
updatedAt: new Date().toISOString(),
29+
updatedAt: new Date(),
3030
},
3131
});
3232
}

src/supply/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ const SupplySchema = z.object({
1212
id: z.string(),
1313
supplyCategoryId: z.string(),
1414
name: z.string().transform(capitalize),
15-
createdAt: z.string(),
16-
updatedAt: z.string().nullable().optional(),
15+
createdAt: z.date(),
16+
updatedAt: z.date().nullable().optional(),
1717
});
1818

1919
const CreateSupplySchema = SupplySchema.omit({

src/users/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const UserSchema = z.object({
1111
password: z.string(),
1212
phone: z.string().transform(removeNotNumbers),
1313
accessLevel: z.nativeEnum(AccessLevel),
14-
createdAt: z.string(),
15-
updatedAt: z.string().nullable().optional(),
14+
createdAt: z.date(),
15+
updatedAt: z.date().nullable().optional(),
1616
});
1717

1818
const CreateUserSchema = UserSchema.pick({

src/users/users.service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class UsersService {
1616
phone,
1717
password: phone,
1818
login: phone,
19-
createdAt: new Date().toISOString(),
19+
createdAt: new Date(),
2020
},
2121
});
2222
}
@@ -29,7 +29,7 @@ export class UsersService {
2929
},
3030
data: {
3131
...payload,
32-
updatedAt: new Date().toISOString(),
32+
updatedAt: new Date(),
3333
},
3434
});
3535
}

0 commit comments

Comments
 (0)