Skip to content

Commit

Permalink
fix: no timezone option (#29)
Browse files Browse the repository at this point in the history
- always use UTC
  • Loading branch information
h4l-yup authored Aug 23, 2023
1 parent 6d65012 commit 36ac69d
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 42 deletions.
1 change: 0 additions & 1 deletion apps/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ npm run migration:run
| AUTO_MIGRATION | set 'true' if you want to make the database migration automatically | |
| MASTER_API_KEY | set a key if you want to make a master key for creating feedback | |
| NODE_OPTIONS | set some options if you want to add for node execution (e.g. max_old_space_size) | |
| TZ | set timezone of the mysql database server if it is not UTC (e.g. +09:00) | +00:00 |

## Learn More

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class TypeOrmConfigService implements TypeOrmOptionsFactory {
logging: ['warn', 'error'],
migrationsRun: process.env.AUTO_MIGRATION === 'true',
namingStrategy: new SnakeNamingStrategy(),
timezone: process.env.TZ,
timezone: '+00:00',
};
}
}
1 change: 0 additions & 1 deletion apps/api/src/configs/mysql.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const mySqlConfigSchema = yup.object({
.default(
'["mysql://userfeedback:userfeedback@localhost:13306/userfeedback"]',
),
TZ: yup.string().default('+00:00'),
});

export const mysqlConfig = registerAs('mysql', () => ({
Expand Down
26 changes: 4 additions & 22 deletions apps/api/src/domains/feedback/feedback.mysql.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,30 +139,12 @@ export class FeedbackMySQLService {
);
} else if (fieldKey === 'createdAt') {
const { gte, lt } = value as TimeRange;
queryBuilder.andWhere(
'CONVERT_TZ(feedbacks.created_at, :timezone, "+00:00") >= :gte',
{ timezone: process.env.TZ, gte },
);
queryBuilder.andWhere(
'CONVERT_TZ(feedbacks.created_at, :timezone, "+00:00") < :lt',
{ timezone: process.env.TZ, lt },
);
queryBuilder.andWhere('feedbacks.created_at >= :gte', { gte });
queryBuilder.andWhere('feedbacks.created_at < :lt', { lt });
} else if (fieldKey === 'updatedAt') {
const { gte, lt } = value as TimeRange;
queryBuilder.andWhere(
'CONVERT_TZ(feedbacks.updated_at, :timezone, "+00:00") >= :gte',
{
timezone: process.env.TZ,
gte,
},
);
queryBuilder.andWhere(
'CONVERT_TZ(feedbacks.updated_at, :timezone, "+00:00") < :lt',
{
timezone: process.env.TZ,
lt,
},
);
queryBuilder.andWhere('feedbacks.updated_at >= :gte', { gte });
queryBuilder.andWhere('feedbacks.updated_at < :lt', { lt });
} else {
const { id, format, type } = fields.find((v) => v.key === fieldKey);

Expand Down
6 changes: 2 additions & 4 deletions apps/api/src/domains/project/issue/issue.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,14 @@ export class IssueService {

if (query.createdAt) {
andWhere.createdAt = Raw(
(alias) =>
`CONVERT_TZ(${alias}, '${process.env.TZ}', '+00:00') >= :gte AND CONVERT_TZ(${alias}, '${process.env.TZ}', '+00:00') < :lt`,
(alias) => `${alias} >= :gte AND ${alias} < :lt`,
query.createdAt as TimeRange,
);
}

if (query.updatedAt) {
andWhere.updatedAt = Raw(
(alias) =>
`CONVERT_TZ(${alias}, '${process.env.TZ}', '+00:00') >= :gte AND CONVERT_TZ(${alias}, '${process.env.TZ}', '+00:00') < :lt`,
(alias) => `${alias} >= :gte AND ${alias} < :lt`,
query.updatedAt as TimeRange,
);
}
Expand Down
12 changes: 4 additions & 8 deletions apps/api/src/domains/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,10 @@ export class UserService {
const { lt, gte } = value as any;
return {
...prev,
createdAt: Raw(
(alias) =>
`CONVERT_TZ(${alias}, '${process.env.TZ}', '+00:00') >= :gte AND CONVERT_TZ(${alias}, '${process.env.TZ}', '+00:00') < :lt`,
{
lt,
gte,
},
),
createdAt: Raw((alias) => `${alias} >= :gte AND ${alias} < :lt`, {
lt,
gte,
}),
};
}
return { ...prev, [key]: Like(`%${value}%`) };
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/utils/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const TestTypeOrmConfig = TypeOrmModule.forRootAsync({
entities: [join(__dirname, '../**/*.entity.{ts,js}')],
logging: ['warn', 'error'],
namingStrategy: new SnakeNamingStrategy(),
timezone: process.env.TZ,
timezone: '+00:00',
};
},
});
Expand Down
13 changes: 9 additions & 4 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
"$schema": "https://turbo.build/schema.json",
"pipeline": {
"build": {
"outputs": ["dist/**", ".next/**", "public/dist/**"],
"dependsOn": ["^build"],
"outputs": [
"dist/**",
".next/**",
"public/dist/**"
],
"dependsOn": [
"^build"
],
"env": [
"NODE_ENV",
"TZ",
"SESSION_PASSWORD",
"API_BASE_URL",
"NEXT_PUBLIC_API_BASE_URL",
Expand Down Expand Up @@ -38,4 +43,4 @@
"cache": false
}
}
}
}

0 comments on commit 36ac69d

Please sign in to comment.