Skip to content

Commit

Permalink
Change happened_on field to datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
big213 committed Mar 4, 2021
1 parent 19aa005 commit 70dc1f1
Show file tree
Hide file tree
Showing 32 changed files with 730 additions and 658 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as Knex from "knex";

export async function up(knex: Knex): Promise<void> {
return knex.schema.alterTable("personalBest", function (t) {
t.dateTime("happened_on").notNullable().alter();
});
}

export async function down(knex: Knex): Promise<void> {
return knex.schema.alterTable("personalBest", function (t) {
t.date("happened_on").notNullable().alter();
});
}
2 changes: 1 addition & 1 deletion backend/functions/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function up(knex: Knex): Promise<void[]> {
table.integer("attempts_succeeded").notNullable();
table.integer("attempts_total").notNullable();
table.integer("product").nullable();
table.date("happened_on").notNullable();
table.dateTime("happened_on").notNullable();
table.integer("time_elapsed").notNullable();
table.dateTime("created_at").notNullable().defaultTo(knex.fn.now());
table.dateTime("updated_at").nullable();
Expand Down
6 changes: 3 additions & 3 deletions backend/functions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backend/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"express": "^4.17.1",
"firebase-admin": "^9.2.0",
"firebase-functions": "^3.13.1",
"jomql": "^0.3.12",
"jomql": "^0.3.13",
"jsonwebtoken": "^8.5.1",
"knex": "^0.21.17",
"pg": "^8.5.1",
Expand Down
9 changes: 4 additions & 5 deletions backend/functions/src/schema/helpers/typeDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ export function generateStringField(
});
}

// as UNIX timestamp
export function generateDateTimeField(
// DateTime as UNIX timestamp
export function generateUnixTimestampField(
params: {
nowOnly?: boolean; // if the unix timestamp can only be set to now()
} & GenerateFieldParams
Expand Down Expand Up @@ -184,7 +184,6 @@ export function generateDateTimeField(
parseValue: nowOnly
? () => knex.fn.now()
: (value: unknown) => {
console.log(value);
if (typeof value !== "number") throw 1; // should never happen
return new Date(value);
},
Expand Down Expand Up @@ -426,7 +425,7 @@ export function generateEnumField(
*/

export function generateCreatedAtField() {
return generateDateTimeField({
return generateUnixTimestampField({
name: "created_at",
description: "When the record was created",
allowNull: false,
Expand All @@ -436,7 +435,7 @@ export function generateCreatedAtField() {
}

export function generateUpdatedAtField() {
return generateDateTimeField({
return generateUnixTimestampField({
name: "updated_at",
description: "When the record was last updated",
allowNull: true,
Expand Down
10 changes: 6 additions & 4 deletions backend/functions/src/schema/models/personalBest/service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { PaginatedService } from "../../core/services";
import { generateUserRoleGuard } from "../../helpers/permissions";
import { userRoleKenum } from "../../enums";
import { permissionsCheck } from "../../helpers/permissions";
import * as Resolver from "../../helpers/resolver";
import * as errorHelper from "../../helpers/error";
import * as sqlHelper from "../../helpers/sql";
import { ServiceFunctionInputs } from "../../../types";
import { JomqlBaseError } from "jomql";
Expand All @@ -29,6 +26,11 @@ export class PersonalBestService extends PaginatedService {
id: {},
created_at: {},
score: {},
"event.name": {},
"pb_class.name": {},
set_size: {},
time_elapsed: {},
happened_on: {},
};

searchFieldsMap = {
Expand Down Expand Up @@ -208,7 +210,7 @@ export class PersonalBestService extends PaginatedService {
fieldPath,
options: {
onConflict: {
columns: ["pb_class", "event", "set_size"],
columns: ["pb_class", "event", "set_size", "created_by"],
action: "merge",
},
},
Expand Down
5 changes: 2 additions & 3 deletions backend/functions/src/schema/models/personalBest/typeDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import {
generateIdField,
generateCreatedAtField,
generateUpdatedAtField,
generateCreatedByField,
generateTypenameField,
generateJoinableField,
generateIntegerField,
generateDateField,
generateUnixTimestampField,
} from "../../helpers/typeDef";

export default new JomqlObjectType(<ObjectTypeDefinition>{
Expand Down Expand Up @@ -59,7 +58,7 @@ export default new JomqlObjectType(<ObjectTypeDefinition>{
service: Product,
allowNull: true,
}),
happened_on: generateDateField({
happened_on: generateUnixTimestampField({
allowNull: false,
}),
time_elapsed: generateIntegerField({
Expand Down
10 changes: 8 additions & 2 deletions frontend/components/interface/crud/crudRecordInterface.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@
</v-badge>
</v-btn>
<v-spacer></v-spacer>
<v-btn icon :loading="loading.exportData" @click="exportData()">
<v-btn
v-if="recordInfo.paginationOptions.downloadOptions"
icon
:loading="loading.exportData"
@click="exportData()"
>
<v-icon>mdi-download</v-icon>
</v-btn>
<v-btn icon @click="syncFilters() || reset()">
Expand All @@ -66,7 +71,7 @@
<v-container v-if="showFilterInterface" fluid class="pb-0 mt-3">
<v-row>
<v-col
v-if="recordInfo.hasSearch"
v-if="recordInfo.paginationOptions.hasSearch"
:key="-1"
sm="12"
lg="3"
Expand Down Expand Up @@ -113,6 +118,7 @@
autocomplete="off"
v-bind="attrs"
v-on="on"
@change="filterChanged = true"
></v-text-field>
</template>
<v-date-picker
Expand Down
13 changes: 6 additions & 7 deletions frontend/components/interface/crud/deleteRecordInterface.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
</template>

<script>
import sharedService from '~/services/shared'
import { executeJomql } from '~/services/jomql'
import { capitalizeString } from '~/services/common'
import { capitalizeString, handleError } from '~/services/common'
export default {
props: {
Expand Down Expand Up @@ -51,8 +50,8 @@ export default {
: this.selectedItem
},
capitalizedType() {
return capitalizeString(this.recordInfo.type)
capitalizedTypename() {
return capitalizeString(this.recordInfo.typename)
},
},
Expand All @@ -62,7 +61,7 @@ export default {
try {
const data = await executeJomql(this, {
[this.recordInfo.deleteOptions.operationName ??
'delete' + this.capitalizedType]: {
'delete' + this.capitalizedTypename]: {
id: true,
__args: {
id: this.selectedItem.id,
Expand All @@ -71,13 +70,13 @@ export default {
})
this.$notifier.showSnackbar({
message: this.capitalizedType + ' Deleted',
message: this.capitalizedTypename + ' Deleted',
variant: 'success',
})
this.$emit('handleSubmit', data)
} catch (err) {
sharedService.handleError(err, this.$root)
handleError(this, err)
}
this.loading.deleteRecord = false
},
Expand Down
3 changes: 1 addition & 2 deletions frontend/components/interface/crud/editRecordInterface.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
v-for="(item, i) in inputsArray"
:key="i"
cols="12"
xs="12"
class="py-0"
>
<div
Expand All @@ -28,7 +27,6 @@
<v-img :src="item.value" contain></v-img>
</v-avatar>
</div>

<v-textarea
v-else-if="item.fieldInfo.inputType === 'textarea'"
v-model="item.value"
Expand Down Expand Up @@ -78,6 +76,7 @@
v-model="item.value"
color="primary"
no-title
:readonly="item.readonly || mode === 'view'"
@input="item.focused = false"
></v-date-picker>
</v-menu>
Expand Down
26 changes: 14 additions & 12 deletions frontend/components/page/crudRecordPage.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<v-container fluid>
<v-layout column justify-left align-left>
<v-flex xs12 sm8 md6>
<div class="pt-2">
<v-row>
<v-col cols="12">
<component
:is="interfaceComponent"
:record-info="recordInfo"
Expand All @@ -16,16 +16,15 @@
dense
@filters-updated="handleFiltersUpdated"
></component>
</div>
</v-flex>
</v-col>
</v-row>
</v-layout>
</v-container>
</template>

<script>
import sharedService from '~/services/shared'
import CrudRecordInterface from '~/components/interface/crud/crudRecordInterface.vue'
import { isObject } from '~/services/common'
import { isObject, capitalizeString } from '~/services/common'
export default {
props: {
Expand Down Expand Up @@ -60,11 +59,14 @@ export default {
},
computed: {
interfaceComponent() {
return this.recordInfo.interfaceComponent || CrudRecordInterface
return (
this.recordInfo.paginationOptions.interfaceComponent ||
CrudRecordInterface
)
},
capitalizedType() {
return sharedService.capitalizeString(this.recordInfo.type)
capitalizedTypename() {
return capitalizeString(this.recordInfo.typename)
},
// parses the query params and transforms into raw filterArray
Expand All @@ -75,7 +77,7 @@ export default {
const decoded = decodeURIComponent(ele)
const filterParts = decoded.split(' ')
if (filterParts.length === 3) {
const filter = this.recordInfo.filters.find(
const filter = this.recordInfo.paginationOptions.filters.find(
(filterObject) => filterObject.field === filterParts[0]
)
Expand All @@ -86,8 +88,8 @@ export default {
if (!fieldInfo) throw new Error('Unknown field: ' + filter.field)
// if value === '_null' it is understood to be null.
const value = fieldInfo.parseValue
? fieldInfo.parseValue(filterParts[2])
const value = fieldInfo.parseQueryValue
? fieldInfo.parseQueryValue(filterParts[2])
: filterParts[2]
filterArray.push({
field: filterParts[0],
Expand Down
Loading

0 comments on commit 70dc1f1

Please sign in to comment.