Skip to content

[WIP] Remove 26 lines of identical code in 4 locations#7

Merged
CropWatchDevelopment merged 1 commit intomasterfrom
copilot/remove-duplicate-code
Jan 20, 2026
Merged

[WIP] Remove 26 lines of identical code in 4 locations#7
CropWatchDevelopment merged 1 commit intomasterfrom
copilot/remove-duplicate-code

Conversation

Copy link
Contributor

Copilot AI commented Jan 20, 2026

Plan: Remove Code Duplication Using NestJS Best Practices

  • Create a shared TimezoneFormatterService in the common directory
    • Extract the three duplicate methods: assertValidTimeZone, formatTimestamp, and getTimeZoneOffset
    • Make it an injectable NestJS service
  • Create a CommonModule to provide the TimezoneFormatterService
  • Update the four affected service files to use the shared service:
    • Update air.service.ts
    • Update soil.service.ts
    • Update traffic.service.ts
    • Update water.service.ts
  • Create tests for the new TimezoneFormatterService
  • Run existing tests to ensure no regression
  • Run lint and build to verify code quality
  • Request code review
  • Run security scan
Original prompt

This section details on the original issue you should resolve

<issue_title>Qlty: Found 26 lines of identical code in 4 locations (mass = 186)</issue_title>
<issue_description>Issue on Qlty

Found 26 lines of identical code in 4 locations (mass = 186)
Duplication
TypeScript
Medium
Found in 4 files
IgnoreOpen GitHub Issue
Found 26 lines of identical code in 4 locations (mass = 186)
src/air/air.service.ts

const
date =
new

Date
(value);

if
(
Number
.isNaN(date.getTime())) {

return
value;
}

if
(!timeZone) {

return
date.toISOString();
}

const
parts =
new

Intl
.DateTimeFormat(
'en-US'
, {
Found 26 lines of identical code in 4 locations (mass = 186)
src/soil/soil.service.ts

const
date =
new

Date
(value);

if
(
Number
.isNaN(date.getTime())) {

return
value;
}

if
(!timeZone) {

return
date.toISOString();
}

const
parts =
new

Intl
.DateTimeFormat(
'en-US'
, {
Found 26 lines of identical code in 4 locations (mass = 186)
src/traffic/traffic.service.ts

const
date =
new

Date
(value);

if
(
Number
.isNaN(date.getTime())) {

return
value;
}

if
(!timeZone) {

return
date.toISOString();
}

const
parts =
new

Intl
.DateTimeFormat(
'en-US'
, {
Found 26 lines of identical code in 4 locations (mass = 186)
src/water/water.service.ts

const
date =
new

Date
(value);

if
(
Number
.isNaN(date.getTime())) {

return
value;
}

if
(!timeZone) {

return
date.toISOString();
}

const
parts =
new

Intl
.DateTimeFormat(
'en-US'
, {</issue_description>

<agent_instructions>please resolve the code duplications using a consistant design pattern that is best practice for nestjs and ensure maintainability as the top priority.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@vercel
Copy link

vercel bot commented Jan 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
api Ready Ready Preview, Comment Jan 20, 2026 3:07am

Request Review

@CropWatchDevelopment CropWatchDevelopment marked this pull request as ready for review January 20, 2026 03:08
@CropWatchDevelopment CropWatchDevelopment merged commit ef082bc into master Jan 20, 2026
2 of 3 checks passed
Copilot stopped work on behalf of CropWatchDevelopment due to an error January 20, 2026 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Qlty: Found 26 lines of identical code in 4 locations (mass = 186)

2 participants