Skip to content

Commit

Permalink
Merge pull request #30 from icefoganalytics/main
Browse files Browse the repository at this point in the history
Fixing offline submissions
  • Loading branch information
datajohnson authored Jul 30, 2024
2 parents 3afe30a + b0de2e1 commit 978ed57
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 7 deletions.
15 changes: 15 additions & 0 deletions api/src/data/migrations/029.drop_auth_index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as knex from "knex";

export async function up(knex: knex.Knex) {
return knex.schema.alterTable("users", (table) => {
table.dropChecks("unique_users_auth_subject")
});
}

export async function down(knex: knex.Knex) {
return knex.schema.alterTable("users", (table) => {
table.unique(["auth_subject"], {
indexName: "unique_users_auth_subject",
});
});
}
8 changes: 6 additions & 2 deletions api/src/routes/offline-report-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@ const userService = new UserService();
offlineReportRouter.post("/", async (req: Request, res: Response) => {
const {} = req.body;

let currentUserEmail = req.body.email;
let currentUserEmail = req.body.on_behalf_email;
let currentUserId = 1;
let currentUserName = req.body.email;
let currentUserName = req.body.on_behalf_email;

const existingUser = await userService.getByEmail(currentUserEmail);

if (existingUser) {
currentUserId = existingUser.id;
currentUserEmail = existingUser.email;
currentUserName = existingUser.display_name;

console.log("Using Existing user", req.body.on_behalf_email);
} else {
console.log("Creating new user", req.body.on_behalf_email);

const createdUser = await userService.create({
department: "",
division: "",
Expand Down
2 changes: 1 addition & 1 deletion api/src/services/user-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class UserService {

async getByEmail(email: string): Promise<User | undefined> {
if (email) {
let user = await db<User>("users").where({ email }).first();
let user = await db<User>("users").whereRaw(`LOWER("email") = '${email.toLowerCase()}'`).first();
if (user) user.roles = await roleService.getRolesForUser(user.id);
return user;
}
Expand Down
2 changes: 1 addition & 1 deletion web/public/serviceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ registerRoute(
plugins: [
new ExpirationPlugin({
maxEntries: 16,
maxAgeSeconds: 120,
maxAgeSeconds: 30 * 24 * 60, // 30 days
}),
],
})
Expand Down
9 changes: 7 additions & 2 deletions web/src/components/incident/CreatePageOffline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
Incident investigation and corrective action. For further information, contant the Director of Health, Safety &
Wellbeing at 867-332-5974.
</p>
<v-overlay v-model="isLoading" class="align-center justify-center">
<div class="text-center">
<v-progress-circular indeterminate size="64" class="mb-5" color="#f3b228" width="6"></v-progress-circular>
</div>
</v-overlay>

<v-form class="mt-6" v-model="isValid">
<section>
Expand Down Expand Up @@ -103,7 +108,7 @@
<v-row>
<v-col cols="12" sm="6" class="py-0">
<v-label>Your email</v-label>
<v-text-field v-model="report.email" :rules="[requiredRule, emailRule]" type="email" />
<v-text-field v-model="report.on_behalf_email" :rules="[requiredRule, emailRule]" type="email" />
</v-col>
<v-col cols="12" sm="6" class="py-0">
<v-label>Supervisor's email</v-label>
Expand Down Expand Up @@ -134,7 +139,7 @@ import { requiredRule, emailRule } from "@/utils/validation";
const reportStore = useReportStore();
const { initialize, addReportOffline } = reportStore;
const { locations, urgencies } = storeToRefs(reportStore);
const { locations, urgencies, isLoading } = storeToRefs(reportStore);
const isValid = ref(false);
Expand Down
6 changes: 5 additions & 1 deletion web/src/store/ReportStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const useReportStore = defineStore("reports", {
locations: [] as Location[],
urgencies: [] as Urgency[],
selectedReport: undefined as Incident | undefined,
isLoading: false,
}),
actions: {
async initialize() {
Expand Down Expand Up @@ -89,6 +90,7 @@ export const useReportStore = defineStore("reports", {

async addReportOffline(report: Incident) {
console.log("ADDREPORTOFFLINE", report);
this.isLoading = true;

const api = useApiStore();

Expand All @@ -107,7 +109,9 @@ export const useReportStore = defineStore("reports", {
formData.append("files", file);
}

return api.upload("post", `${OFFLINEREPORTS_URL}`, formData);
return api.upload("post", `${OFFLINEREPORTS_URL}`, formData).finally(() => {
this.isLoading = false;
});

/* const storedJson = this.getStoredReports();
storedJson.push(report);
Expand Down

0 comments on commit 978ed57

Please sign in to comment.