Skip to content

Commit 53385eb

Browse files
authored
Merge pull request #78 from wbbly/dev
ADD | search bar , filters on team-page + small fixes
2 parents e5df471 + baecaa9 commit 53385eb

6 files changed

Lines changed: 129 additions & 15 deletions

File tree

app/src/schedule/schedule.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { TimerCurrentV2Module } from '../timer-current-v2/timer-current-v2.modul
55
import { TimeModule } from '../time/time.module';
66
import { ScheduleService } from './schedule.service';
77
import { InvoiceModule } from '../invoice/invoice.module';
8+
import { TimerModule } from '../timer/timer.module';
89

910
@Module({
10-
imports: [CoreModule, TimerCurrentV2Module, TimeModule, InvoiceModule],
11+
imports: [CoreModule, TimerCurrentV2Module, TimeModule, InvoiceModule, TimerModule],
1112
providers: [ScheduleService],
1213
})
1314
export class ScheduleModule {}

app/src/schedule/schedule.service.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ import { TimerCurrentV2Service } from '../timer-current-v2/timer-current-v2.serv
66
import { TimeService } from '../time/time.service';
77
import { TimerCurrentV2 } from '../timer-current-v2/interfaces/timer-current-v2.interface';
88
import { InvoiceService } from '../invoice/invoice.service';
9+
import { TimerService } from '../timer/timer.service';
910

1011
@Injectable()
1112
export class ScheduleService extends NestSchedule {
1213
constructor(
1314
private readonly mailService: MailService,
1415
private readonly timerCurrentV2Service: TimerCurrentV2Service,
1516
private readonly timeService: TimeService,
16-
private readonly invoiceService: InvoiceService
17+
private readonly invoiceService: InvoiceService,
18+
private readonly timerService: TimerService
1719
) {
1820
super();
1921
}
@@ -104,4 +106,16 @@ export class ScheduleService extends NestSchedule {
104106
console.log(err);
105107
}
106108
}
109+
110+
@Cron('0 0 * * *') // check every day at midnight for empty title field in timer_v2 table and write decoded issue field to it
111+
async checkForEmptyTimerTitle() {
112+
try {
113+
const timers = await this.timerService.getTimersWithoutTitle();
114+
for (const timer of timers) {
115+
await this.timerService.setTimerTitleFromIssue(timer.id, decodeURI(timer.issue));
116+
}
117+
} catch (error) {
118+
console.log(error);
119+
}
120+
}
107121
}

app/src/timer-current-v2/timer-current-v2.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ export class TimerCurrentV2Service {
290290
endDatetime: this.timeService.getISOTimeWithZeroMilliseconds(),
291291
userId: user.id,
292292
projectId: project.id,
293+
title: decodeURI(issue),
293294
})
294295
.then((res: Timer) => resolve(res), _ => reject(null))
295296
.catch(_ => reject(null));

app/src/timer/interfaces/timer.interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ export interface Timer {
1313
createdAt?: string;
1414
project?: Project;
1515
user?: User;
16+
title?: string;
1617
}

app/src/timer/timer.controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ export class TimerController {
3333
async userTimerList(
3434
@Headers() headers: any,
3535
@Response() res: any,
36-
@Query() params: { page?: string; limit?: string }
36+
@Query()
37+
params: { page?: string; limit?: string; startDateTime?: string; endDateTime?: string; searchValue?: string }
3738
) {
3839
const userId = await this.authService.getVerifiedUserId(headers.authorization);
3940
if (!userId) {
4041
throw new UnauthorizedException();
4142
}
42-
4343
if (Object.keys(params).length) {
4444
const { page, limit } = params;
4545
if (!Number.parseInt(page) || !Number.parseInt(limit) || +page <= 0 || +limit <= 0) {

app/src/timer/timer.service.ts

Lines changed: 108 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,27 @@ export class TimerService {
103103
projectId: string;
104104
jiraWorklogId?: number;
105105
syncJiraStatus?: boolean;
106+
title?: string;
106107
}): Promise<Timer | null> {
107108
let { issue } = data;
108109
issue = issue || 'Untitled issue';
109110

110-
const { startDatetime, endDatetime, userId, projectId, jiraWorklogId = null, syncJiraStatus = false } = data;
111+
const {
112+
startDatetime,
113+
endDatetime,
114+
userId,
115+
projectId,
116+
jiraWorklogId = null,
117+
syncJiraStatus = false,
118+
title,
119+
} = data;
111120

112121
const query = `mutation {
113122
insert_timer_v2(
114123
objects: [
115124
{
116125
issue: "${issue}",
126+
title: "${title.replace(/"/g, '\\"')}",
117127
start_datetime: "${startDatetime}",
118128
end_datetime: "${endDatetime}",
119129
user_id: "${userId}"
@@ -146,7 +156,10 @@ export class TimerService {
146156
});
147157
}
148158

149-
getUserTimerList(userId: string, params: { page?: string; limit?: string }) {
159+
getUserTimerList(
160+
userId: string,
161+
params: { page?: string; limit?: string; startDateTime?: string; endDateTime?: string; searchValue?: string }
162+
) {
150163
const getCurrentTeamQuery = `{
151164
user_team(where: {
152165
user_id: { _eq: "${userId}" },
@@ -159,14 +172,27 @@ export class TimerService {
159172
}
160173
}`;
161174

162-
let { page, limit } = params;
175+
let { page, limit, startDateTime, endDateTime, searchValue } = params;
163176
let amountQuery = '';
177+
let dateRangeQuery = '';
178+
let searchQuery = '';
164179

165180
if (page && limit) {
166181
const offset = +page === 1 ? 0 : +limit * (+page - 1);
167182
amountQuery = `limit: ${limit}, offset: ${offset}`;
168183
}
169184

185+
if (startDateTime && endDateTime) {
186+
dateRangeQuery = `start_datetime: {_gte: "${startDateTime}", _lte: "${endDateTime}"}`;
187+
}
188+
189+
if (searchValue) {
190+
searchQuery = `title: {_ilike: "%${searchValue
191+
.toLowerCase()
192+
.trim()
193+
.replace(/"/g, '\\"')}%"}`;
194+
}
195+
170196
return new Promise((resolve, reject) => {
171197
this.httpRequestsService.request(getCurrentTeamQuery).subscribe(
172198
(getCurrentTeamRes: AxiosResponse) => {
@@ -179,18 +205,36 @@ export class TimerService {
179205
console.log(e);
180206
}
181207

182-
const query = `{ timer_v2(
208+
const variables: any = {
183209
where: {
184-
user_id: {_eq: "${userId}"},
210+
user_id: {
211+
_eq: userId,
212+
},
185213
project: {
186214
team_id: {
187-
_eq: "${teamId}"
188-
}
215+
_eq: teamId,
216+
},
189217
},
190218
},
191-
${amountQuery}
192-
order_by: {start_datetime: desc},
193-
) {
219+
};
220+
if (startDateTime && endDateTime) {
221+
variables.where.start_datetime = {
222+
_gte: startDateTime,
223+
_lte: endDateTime,
224+
};
225+
}
226+
if (searchValue) {
227+
variables.where.title = {
228+
_ilike: `%${searchValue
229+
.toLowerCase()
230+
.trim()
231+
.replace(/%/g, '\\%')}%`,
232+
};
233+
}
234+
235+
const query = `query timer($where: timer_v2_bool_exp){
236+
timer_v2( where: $where, order_by: {start_datetime: desc}, ${amountQuery})
237+
{
194238
id,
195239
start_datetime,
196240
end_datetime,
@@ -207,7 +251,7 @@ export class TimerService {
207251
}`;
208252

209253
this.httpRequestsService
210-
.request(query)
254+
.graphql(query, variables)
211255
.subscribe((res: AxiosResponse) => resolve(res), (error: AxiosError) => reject(error));
212256
},
213257
(getCurrentTeamError: AxiosError) => reject(getCurrentTeamError)
@@ -281,6 +325,9 @@ export class TimerService {
281325
if (endDatetime) {
282326
setParams.push(`end_datetime: "${endDatetime}"`);
283327
}
328+
if (issue) {
329+
setParams.push(`title: "${decodeURI(issue).replace(/"/g, '\\"')}"`);
330+
}
284331

285332
const getTimerQuery = `{
286333
timer_v2(where: {id: {_eq: "${timerId}"}}) {
@@ -446,4 +493,54 @@ export class TimerService {
446493

447494
return timeEntry;
448495
}
496+
497+
async getTimersWithoutTitle(): Promise<Timer[] | null> {
498+
const query = `{
499+
timer_v2(where: {title: {_is_null: true}}) {
500+
id
501+
issue
502+
title
503+
}
504+
}`;
505+
506+
return new Promise((resolve, reject) => {
507+
this.httpRequestsService
508+
.request(query)
509+
.subscribe((res: AxiosResponse) => resolve(res.data.timer_v2), (error: AxiosError) => reject(error));
510+
});
511+
}
512+
513+
async setTimerTitleFromIssue(id: string, title: string): Promise<Timer | null> {
514+
const variables = {
515+
where: {
516+
id: {
517+
_eq: id,
518+
},
519+
},
520+
_set: {
521+
title,
522+
},
523+
};
524+
const mutation = `
525+
mutation updateTimer($where: timer_v2_bool_exp!, $_set: timer_v2_set_input) {
526+
update_timer_v2(_set: $_set, where: $where) {
527+
returning {
528+
id
529+
issue
530+
title
531+
}
532+
}
533+
}
534+
`;
535+
536+
return new Promise((resolve, reject) => {
537+
this.httpRequestsService.graphql(mutation, variables).subscribe(
538+
(res: AxiosResponse) => resolve(res.data.update_timer_v2.returning[0]),
539+
(error: AxiosError) => {
540+
console.log(error.response.data);
541+
reject(error);
542+
}
543+
);
544+
});
545+
}
449546
}

0 commit comments

Comments
 (0)