Skip to content

Commit 90127e5

Browse files
committed
Fix time
1 parent 0fc6efe commit 90127e5

4 files changed

Lines changed: 59 additions & 53 deletions

File tree

api/pkg/repositories/gorm_phone_notification_repository.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (repository *gormPhoneNotificationRepository) Schedule(
9999
schedule *entities.MessageSendSchedule,
100100
notification *entities.PhoneNotification,
101101
) error {
102-
ctx, span := repository.tracer.Start(ctx)
102+
ctx, span, _ := repository.tracer.StartWithLogger(ctx, repository.logger)
103103
defer span.End()
104104

105105
now := time.Now().UTC()
@@ -174,7 +174,7 @@ func (repository *gormPhoneNotificationRepository) resolveScheduledAt(
174174
return schedule.ResolveScheduledAt(current)
175175
}
176176

177-
// maxTime returns the later of the two times.
177+
// maxTime returns the greater of the two time.Time.
178178
func (repository *gormPhoneNotificationRepository) maxTime(a, b time.Time) time.Time {
179179
if a.After(b) {
180180
return a

api/pkg/services/phone_notification_service.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,16 @@ func (service *PhoneNotificationService) Schedule(ctx context.Context, params *P
205205
var schedule *entities.MessageSendSchedule
206206
if phone.MessageSendScheduleID != nil {
207207
schedule, err = service.messageSendScheduleRepository.Load(ctx, params.UserID, *phone.MessageSendScheduleID)
208-
if stacktrace.GetCode(err) == repositories.ErrCodeNotFound {
209-
schedule = nil
210-
err = nil
211-
}
212-
if err != nil {
208+
if err != nil && stacktrace.GetCode(err) != repositories.ErrCodeNotFound {
213209
msg := fmt.Sprintf("cannot load send schedule [%s] for phone [%s]", *phone.MessageSendScheduleID, phone.ID)
214210
return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
215211
}
216212
}
217213

214+
if schedule != nil {
215+
ctxLogger.Info(fmt.Sprintf("loaded [%T] with ID [%s] for phone [%s]", schedule, schedule.ID, phone.ID))
216+
}
217+
218218
if err = service.phoneNotificationRepository.Schedule(ctx, phone.MessagesPerMinute, schedule, notification); err != nil {
219219
msg := fmt.Sprintf("cannot schedule notification for message [%s] to phone [%s]", params.MessageID, phone.ID)
220220
return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
@@ -229,10 +229,11 @@ func (service *PhoneNotificationService) Schedule(ctx context.Context, params *P
229229
}
230230

231231
ctxLogger.Info(fmt.Sprintf(
232-
"message with id [%s] notification scheduled for [%s] with id [%s]",
232+
"message with id [%s] notification scheduled for [%s] with id [%s] with phone schedule ID [%s]",
233233
params.MessageID,
234234
notification.ScheduledAt,
235235
notification.ID,
236+
phone.MessageSendScheduleID,
236237
))
237238
return nil
238239
}

web/pages/settings/index.vue

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,8 +1126,8 @@ import { ErrorMessages } from '~/plugins/errors'
11261126
import LoadingButton from '~/components/LoadingButton.vue'
11271127
import {
11281128
EntitiesDiscord,
1129+
EntitiesMessageSendSchedule,
11291130
EntitiesPhone,
1130-
EntitiesSendSchedule,
11311131
EntitiesWebhook,
11321132
} from '~/models/api'
11331133
@@ -1204,7 +1204,7 @@ export default Vue.extend({
12041204
updatingPhone: false,
12051205
updatingDiscord: false,
12061206
loadingDiscordIntegrations: false,
1207-
sendSchedules: [] as EntitiesSendSchedule[],
1207+
sendSchedules: [] as EntitiesMessageSendSchedule[],
12081208
events: [
12091209
'message.phone.received',
12101210
'message.phone.sent',
@@ -1219,13 +1219,11 @@ export default Vue.extend({
12191219
id: null,
12201220
name: '',
12211221
timezone: '',
1222-
is_active: true,
12231222
windows: [],
12241223
} as {
12251224
id: string | null
12261225
name: string
12271226
timezone: string
1228-
is_active: boolean
12291227
windows: Array<{
12301228
day_of_week: number
12311229
start_time: string
@@ -1588,7 +1586,7 @@ export default Vue.extend({
15881586
this.loadingSendSchedules = true
15891587
this.$store
15901588
.dispatch('getSendSchedules')
1591-
.then((sendSchedules: EntitiesSendSchedule[]) => {
1589+
.then((sendSchedules: EntitiesMessageSendSchedule[]) => {
15921590
this.sendSchedules = sendSchedules
15931591
})
15941592
.finally(() => {
@@ -1673,7 +1671,7 @@ export default Vue.extend({
16731671
return this.weekDays.find((x) => x.value == index)?.label ?? ''
16741672
},
16751673
1676-
scheduleSummary(schedule: EntitiesSendSchedule) {
1674+
scheduleSummary(schedule: EntitiesMessageSendSchedule) {
16771675
return this.weekDays
16781676
.map((day) => {
16791677
const windows = (schedule.windows || []).filter(
@@ -1711,7 +1709,6 @@ export default Vue.extend({
17111709
id: null,
17121710
name: '',
17131711
timezone: this.defaultTimezone(),
1714-
is_active: true,
17151712
windows: [
17161713
{ day_of_week: 1, start_time: '09:00', end_time: '17:00' },
17171714
{ day_of_week: 2, start_time: '09:00', end_time: '17:00' },
@@ -1723,16 +1720,12 @@ export default Vue.extend({
17231720
this.showScheduleEdit = true
17241721
},
17251722
1726-
openEditSchedule(schedule: EntitiesSendSchedule) {
1723+
openEditSchedule(schedule: EntitiesMessageSendSchedule) {
17271724
this.resetErrors()
17281725
this.activeSchedule = {
17291726
id: schedule.id,
17301727
name: schedule.name,
17311728
timezone: schedule.timezone,
1732-
is_active:
1733-
typeof schedule.is_active !== 'undefined'
1734-
? schedule.is_active
1735-
: Boolean((schedule as any).active),
17361729
windows: (schedule.windows || []).map((x) => ({
17371730
day_of_week: x.day_of_week,
17381731
start_time: this.minuteToClock(x.start_minute),
@@ -1806,7 +1799,6 @@ export default Vue.extend({
18061799
const payload = {
18071800
name: this.activeSchedule.name,
18081801
timezone: this.activeSchedule.timezone,
1809-
is_active: this.activeSchedule.is_active,
18101802
windows: (this.activeSchedule.windows || []).map((window) => ({
18111803
day_of_week: window.day_of_week,
18121804
start_minute: this.clockToMinute(window.start_time),

web/store/index.ts

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,27 @@ import { BillingUsage } from '~/models/billing'
99
import {
1010
EntitiesDiscord,
1111
EntitiesMessage,
12+
EntitiesMessageSendSchedule,
1213
EntitiesPhone,
1314
EntitiesPhoneAPIKey,
14-
EntitiesSendSchedule,
1515
EntitiesUser,
1616
EntitiesWebhook,
1717
RequestsDiscordStore,
1818
RequestsDiscordUpdate,
19-
RequestsSendScheduleStore,
19+
RequestsMessageSendScheduleStore,
2020
RequestsUserNotificationUpdate,
2121
RequestsUserPaymentInvoice,
2222
RequestsWebhookStore,
2323
RequestsWebhookUpdate,
2424
ResponsesDiscordResponse,
2525
ResponsesDiscordsResponse,
26+
ResponsesMessageSendScheduleResponse,
27+
ResponsesMessageSendSchedulesResponse,
2628
ResponsesMessagesResponse,
2729
ResponsesNoContent,
2830
ResponsesOkString,
2931
ResponsesPhoneAPIKeyResponse,
3032
ResponsesPhoneAPIKeysResponse,
31-
ResponsesSendScheduleResponse,
32-
ResponsesSendSchedulesResponse,
3333
ResponsesUnprocessableEntity,
3434
ResponsesUserResponse,
3535
ResponsesUserSubscriptionPaymentsResponse,
@@ -381,7 +381,7 @@ export const actions = {
381381
missed_call_auto_reply: phone.missed_call_auto_reply,
382382
max_send_attempts: parseInt(phone.max_send_attempts.toString()),
383383
messages_per_minute: parseInt(phone.messages_per_minute.toString()),
384-
schedule_id: phone.schedule_id ?? null,
384+
message_send_schedule_id: phone.message_send_schedule_id ?? null,
385385
})
386386

387387
context.dispatch('addNotification', {
@@ -1109,34 +1109,45 @@ export const actions = {
11091109
},
11101110

11111111
getSendSchedules(context: ActionContext<State, State>) {
1112-
return new Promise<Array<EntitiesSendSchedule>>((resolve, reject) => {
1113-
axios
1114-
.get<ResponsesSendSchedulesResponse>(`/v1/send-schedules`)
1115-
.then((response: AxiosResponse<ResponsesSendSchedulesResponse>) => {
1116-
resolve(response.data.data)
1117-
})
1118-
.catch(async (error: AxiosError) => {
1119-
await context.dispatch('addNotification', {
1120-
message:
1121-
(error.response?.data as any)?.message ??
1122-
'Error while fetching send schedules',
1123-
type: 'error',
1112+
return new Promise<Array<EntitiesMessageSendSchedule>>(
1113+
(resolve, reject) => {
1114+
axios
1115+
.get<ResponsesMessageSendSchedulesResponse>(`/v1/send-schedules`)
1116+
.then(
1117+
(
1118+
response: AxiosResponse<ResponsesMessageSendSchedulesResponse>,
1119+
) => {
1120+
resolve(response.data.data)
1121+
},
1122+
)
1123+
.catch(async (error: AxiosError) => {
1124+
await context.dispatch('addNotification', {
1125+
message:
1126+
(error.response?.data as any)?.message ??
1127+
'Error while fetching send schedules',
1128+
type: 'error',
1129+
})
1130+
reject(getErrorMessages(error))
11241131
})
1125-
reject(getErrorMessages(error))
1126-
})
1127-
})
1132+
},
1133+
)
11281134
},
11291135

11301136
createSendSchedule(
11311137
context: ActionContext<State, State>,
1132-
payload: RequestsSendScheduleStore,
1138+
payload: RequestsMessageSendScheduleStore,
11331139
) {
1134-
return new Promise<EntitiesSendSchedule>((resolve, reject) => {
1140+
return new Promise<EntitiesMessageSendSchedule>((resolve, reject) => {
11351141
axios
1136-
.post<ResponsesSendScheduleResponse>(`/v1/send-schedules`, payload)
1137-
.then((response: AxiosResponse<ResponsesSendScheduleResponse>) => {
1138-
resolve(response.data.data)
1139-
})
1142+
.post<ResponsesMessageSendScheduleResponse>(
1143+
`/v1/send-schedules`,
1144+
payload,
1145+
)
1146+
.then(
1147+
(response: AxiosResponse<ResponsesMessageSendScheduleResponse>) => {
1148+
resolve(response.data.data)
1149+
},
1150+
)
11401151
.catch(async (error: AxiosError) => {
11411152
await context.dispatch('addNotification', {
11421153
message:
@@ -1151,17 +1162,19 @@ export const actions = {
11511162

11521163
updateSendSchedule(
11531164
context: ActionContext<State, State>,
1154-
payload: RequestsSendScheduleStore & { id: string },
1165+
payload: RequestsMessageSendScheduleStore & { id: string },
11551166
) {
1156-
return new Promise<EntitiesSendSchedule>((resolve, reject) => {
1167+
return new Promise<EntitiesMessageSendSchedule>((resolve, reject) => {
11571168
axios
1158-
.put<ResponsesSendScheduleResponse>(
1169+
.put<ResponsesMessageSendScheduleResponse>(
11591170
`/v1/send-schedules/${payload.id}`,
11601171
payload,
11611172
)
1162-
.then((response: AxiosResponse<ResponsesSendScheduleResponse>) => {
1163-
resolve(response.data.data)
1164-
})
1173+
.then(
1174+
(response: AxiosResponse<ResponsesMessageSendScheduleResponse>) => {
1175+
resolve(response.data.data)
1176+
},
1177+
)
11651178
.catch(async (error: AxiosError) => {
11661179
await context.dispatch('addNotification', {
11671180
message:

0 commit comments

Comments
 (0)