Skip to content

Commit

Permalink
fix: use number for dateTime
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan-Chew committed Oct 1, 2023
1 parent b937374 commit 5ff66ce
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions components/admin/event/event-information.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const props = defineProps<{
event: EventWithAttendees
}>()
function convertEpochToSGT(epochTime: string) {
const date = new Date(Number.parseInt(epochTime) * 1000)
function convertEpochToSGT(epochTime: number) {
const date = new Date(epochTime * 1000)
const formattedDate = date.toLocaleDateString('en-SG', {
day: '2-digit',
Expand Down
2 changes: 1 addition & 1 deletion components/admin/event/upload-attendees.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function handleFileUpload(e: Event) {
complete(results: ParseResult<Omit<User, 'firebaseId' | 'id'>>) {
uploadedAttendees = results.data
if (JSON.stringify(results.meta.fields?.sort()) !== JSON.stringify(['name', 'memberId', 'email', 'graduationYear', 'memberType'].sort())) {
if (JSON.stringify(results.meta.fields?.sort()) !== JSON.stringify(['name', 'email', 'memberType'].sort())) {
error.value.didError = true
error.value.msg = 'CSV has missing fields! Please check the file and reupload it.'
return
Expand Down
8 changes: 4 additions & 4 deletions components/admin/home/create-event-popup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const event = reactive({
description: '',
location: '',
badgeImage: '',
startDateTime: '',
endDateTime: '',
startDateTime: 0,
endDateTime: 0,
})
const mutation = useMutation({
Expand All @@ -25,8 +25,8 @@ const mutation = useMutation({
const newEventId = ref('')
async function createEvent() {
event.startDateTime = (new Date(event.startDateTime).getTime() / 1000).toString()
event.endDateTime = (new Date(event.endDateTime).getTime() / 1000).toString()
event.startDateTime = new Date(event.startDateTime).getTime() / 1000
event.endDateTime = new Date(event.endDateTime).getTime() / 1000
const res = await mutation.mutateAsync(event)
newEventId.value = res.id
Expand Down
8 changes: 4 additions & 4 deletions components/admin/home/events-table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const selectedEvent = ref<EventWithAttendees>({
description: '',
location: '',
badgeImage: '',
startDateTime: '',
endDateTime: '',
startDateTime: 0,
endDateTime: 0,
attendees: [],
})
Expand Down Expand Up @@ -86,10 +86,10 @@ function showDetails(event: EventWithAttendees) {
{{ event.name }}
</td>
<td class="label-cell" @click="showDetails(event)">
{{ dayjs(parseInt(event.startDateTime) * 1000).format('DD-MM-YYYY HH:mm') }}
{{ dayjs(event.startDateTime).format('DD-MM-YYYY HH:mm') }}
</td>
<td class="label-cell" @click="showDetails(event)">
{{ dayjs(parseInt(event.endDateTime) * 1000).format('DD-MM-YYYY HH:mm') }}
{{ dayjs(event.endDateTime).format('DD-MM-YYYY HH:mm') }}
</td>
<td class="numeric-cell" @click="showDetails(event)">
{{ event.attendees.length }}
Expand Down
12 changes: 6 additions & 6 deletions components/admin/home/update-event-popup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ const updatedValues = reactive({
description: props.event.description,
location: props.event.location,
badgeImage: props.event.badgeImage,
startDateTime: dayjs(Number.parseInt(props.event.startDateTime) * 1000).format('YYYY-MM-DDTHH:mm'),
endDateTime: dayjs(Number.parseInt(props.event.endDateTime) * 1000).format('YYYY-MM-DDTHH:mm'),
startDateTime: dayjs(props.event.startDateTime).format('YYYY-MM-DDTHH:mm'),
endDateTime: dayjs(props.event.endDateTime).format('YYYY-MM-DDTHH:mm'),
})
watch(props, () => {
updatedValues.startDateTime = dayjs(Number.parseInt(props.event.startDateTime) * 1000).format('YYYY-MM-DDTHH:mm')
updatedValues.endDateTime = dayjs(Number.parseInt(props.event.endDateTime) * 1000).format('YYYY-MM-DDTHH:mm')
updatedValues.startDateTime = dayjs(props.event.startDateTime).format('YYYY-MM-DDTHH:mm')
updatedValues.endDateTime = dayjs(props.event.endDateTime).format('YYYY-MM-DDTHH:mm')
})
const mutation = useMutation({
Expand Down Expand Up @@ -57,8 +57,8 @@ async function updateEvent() {
<f7ListInput v-model:value="updatedValues.description" label="Event Description" :placeholder="props.event.description" />
<f7ListInput v-model:value="updatedValues.location" label="Event Location" :placeholder="props.event.location" />
<f7ListInput v-model:value="updatedValues.badgeImage" label="Image URL" :placeholder="props.event.badgeImage" type="url" />
<f7ListInput v-model:value="updatedValues.startDateTime" label="Start Date and Time" :placeholder="props.event.startDateTime" type="datetime-local" />
<f7ListInput v-model:value="updatedValues.endDateTime" label="End Date and Time" :placeholder="props.event.endDateTime" type="datetime-local" />
<f7ListInput v-model:value="updatedValues.startDateTime" label="Start Date and Time" :placeholder="props.event.startDateTime.toString()" type="datetime-local" />
<f7ListInput v-model:value="updatedValues.endDateTime" label="End Date and Time" :placeholder="props.event.endDateTime.toString()" type="datetime-local" />

<f7List inset>
<f7Button v-if="!mutation.isSuccess.value" fill type="submit" preloader :loading="mutation.isLoading.value" :disabled="mutation.isLoading.value">
Expand Down
4 changes: 2 additions & 2 deletions server/api/event/[id].post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const updateEventRequestBody = z.object({
description: z.string(),
location: z.string(),
badgeImage: z.string().url(),
startDateTime: z.string(),
endDateTime: z.string(),
startDateTime: z.number(),
endDateTime: z.number(),
})

export default defineProtectedEventHandler(async (event) => {
Expand Down
4 changes: 2 additions & 2 deletions server/api/event/[id].put.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const updateEventRequestBody = z.object({
description: z.string().optional(),
location: z.string().optional(),
badgeImage: z.string().url().optional(),
startDateTime: z.string().datetime().optional(),
endDateTime: z.string().datetime().optional(),
startDateTime: z.number().optional(),
endDateTime: z.number().optional(),
})

export default defineProtectedEventHandler(async (event) => {
Expand Down
4 changes: 2 additions & 2 deletions server/api/event/index.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const createEventRequestBody = z.object({
description: z.string(),
location: z.string(),
badgeImage: z.string().url(),
startDateTime: z.string(),
endDateTime: z.string(),
startDateTime: z.number(),
endDateTime: z.number(),
})

export default defineProtectedEventHandler(async (event) => {
Expand Down
4 changes: 2 additions & 2 deletions server/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export const events = sqliteTable('events', {
description: text('description').notNull(),
location: text('location').notNull(),
badgeImage: text('badge_image').notNull(),
startDateTime: text('start_date_time').notNull(), // ISO formatted
endDateTime: text('end_date_time').notNull(), // ISO formatted
startDateTime: integer('start_date_time').notNull(), // ISO formatted
endDateTime: integer('end_date_time').notNull(), // ISO formatted
})

export const usersToEvents = sqliteTable('users_events', {
Expand Down

0 comments on commit 5ff66ce

Please sign in to comment.