From 2922ced9714764c2c088100df26fbe6e2eb8d1fa Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Sun, 8 Aug 2021 22:56:05 -0400 Subject: [PATCH] Success stories migrated; closing in on done --- src/JobsJobsJobs/Api/Data.fs | 5 +- src/JobsJobsJobs/Api/Handlers.fs | 6 +- src/JobsJobsJobs/App/src/api/index.ts | 26 +++- src/JobsJobsJobs/App/src/api/types.ts | 10 ++ src/JobsJobsJobs/App/src/router/index.ts | 6 +- .../App/src/views/citizen/EditProfile.vue | 4 +- .../App/src/views/profile/ProfileView.vue | 6 +- .../App/src/views/so-long/DeletionOptions.vue | 6 +- .../App/src/views/so-long/DeletionSuccess.vue | 2 +- .../App/src/views/success-story/StoryAdd.vue | 3 - .../App/src/views/success-story/StoryEdit.vue | 142 ++++++++++++++++++ .../App/src/views/success-story/StoryList.vue | 2 +- .../App/src/views/success-story/StoryView.vue | 3 +- 13 files changed, 198 insertions(+), 23 deletions(-) delete mode 100644 src/JobsJobsJobs/App/src/views/success-story/StoryAdd.vue create mode 100644 src/JobsJobsJobs/App/src/views/success-story/StoryEdit.vue diff --git a/src/JobsJobsJobs/Api/Data.fs b/src/JobsJobsJobs/Api/Data.fs index 9cc7e86..5a6e5ab 100644 --- a/src/JobsJobsJobs/Api/Data.fs +++ b/src/JobsJobsJobs/Api/Data.fs @@ -468,9 +468,10 @@ module Success = .Zip() .Merge(ReqlFunction1(fun it -> upcast r - .HashMap("displayName", + .HashMap("citizenName", r.Branch(it.G("realName" ).Default_("").Ne(""), it.G("realName"), it.G("displayName").Default_("").Ne(""), it.G("displayName"), - it.G("naUser"))))) + it.G("naUser"))) + .With("hasStory", it.G("story").Default_("").Gt("")))) .Pluck("id", "citizenId", "citizenName", "recordedOn", "fromHere", "hasStory") .RunResultAsync conn) diff --git a/src/JobsJobsJobs/Api/Handlers.fs b/src/JobsJobsJobs/Api/Handlers.fs index 8dd3f17..874c6c9 100644 --- a/src/JobsJobsJobs/Api/Handlers.fs +++ b/src/JobsJobsJobs/Api/Handlers.fs @@ -341,7 +341,7 @@ module Success = let! success = task { match form.id with | "new" -> - return Some { id = (Guid.NewGuid >> SuccessId) () + return Some { id = SuccessId.create () citizenId = citizenId recordedOn = now fromHere = form.fromHere @@ -397,8 +397,8 @@ let allEndpoints = [ ] subRoute "/success" [ GET_HEAD [ - routef "/get/%O" Success.get - route "/list" Success.all + routef "/%O" Success.get + route "/list" Success.all ] POST [ route "/save" Success.save ] ] diff --git a/src/JobsJobsJobs/App/src/api/index.ts b/src/JobsJobsJobs/App/src/api/index.ts index 155308e..fd4b103 100644 --- a/src/JobsJobsJobs/App/src/api/index.ts +++ b/src/JobsJobsJobs/App/src/api/index.ts @@ -12,6 +12,7 @@ import { PublicSearch, PublicSearchResult, StoryEntry, + StoryForm, Success } from './types' @@ -137,6 +138,18 @@ export default { /** API functions for profiles */ profile: { + /** + * Clear the "seeking employment" flag on the current citizen's profile + * + * @param user The currently logged-on user + * @returns True if the action was successful, or an error string if not + */ + markEmploymentFound: async (user : LogOnSuccess) : Promise => { + const result = await fetch(apiUrl('profile/employment-found'), reqInit('PATCH', user)) + if (result.ok) return true + return `${result.status} - ${result.statusText} (${await result.text()})` + }, + /** * Search for public profile data using the given parameters * @@ -183,6 +196,7 @@ export default { * * @param data The profile data to be saved * @param user The currently logged-on user + * @returns True if the save was successful, an error string if not */ save: async (data : ProfileForm, user : LogOnSuccess) : Promise => apiSend(await fetch(apiUrl('profile/save'), reqInit('POST', user, data)), 'saving profile'), @@ -249,7 +263,17 @@ export default { * @returns The success story, or an error */ retrieve: async (id : string, user : LogOnSuccess) : Promise => - apiResult(await fetch(apiUrl(`success/${id}`), reqInit('GET', user)), `retrieving success story ${id}`) + apiResult(await fetch(apiUrl(`success/${id}`), reqInit('GET', user)), `retrieving success story ${id}`), + + /** + * Save a success story + * + * @param data The data to be saved + * @param user The currently logged-on user + * @returns True if successful, an error string if not + */ + save: async (data : StoryForm, user : LogOnSuccess) : Promise => + apiSend(await fetch(apiUrl('success/save'), reqInit('POST', user, data)), 'saving success story') } } diff --git a/src/JobsJobsJobs/App/src/api/types.ts b/src/JobsJobsJobs/App/src/api/types.ts index b07c0d2..05e5fb1 100644 --- a/src/JobsJobsJobs/App/src/api/types.ts +++ b/src/JobsJobsJobs/App/src/api/types.ts @@ -179,6 +179,16 @@ export interface StoryEntry { hasStory : boolean } +/** The data required to provide a success story */ +export class StoryForm { + /** The ID of this story */ + id = '' + /** Whether the employment was obtained from Jobs, Jobs, Jobs */ + fromHere = false + /** The success story */ + story = '' +} + /** A record of success finding employment */ export interface Success { /** The ID of the success report */ diff --git a/src/JobsJobsJobs/App/src/router/index.ts b/src/JobsJobsJobs/App/src/router/index.ts index b7b8feb..2f36105 100644 --- a/src/JobsJobsJobs/App/src/router/index.ts +++ b/src/JobsJobsJobs/App/src/router/index.ts @@ -106,9 +106,9 @@ const routes: Array = [ component: () => import(/* webpackChunkName: "success" */ '../views/success-story/StoryList.vue') }, { - path: '/success-story/add', - name: 'AddStory', - component: () => import(/* webpackChunkName: "succedit" */ '../views/success-story/StoryAdd.vue') + path: '/success-story/edit/:id', + name: 'EditStory', + component: () => import(/* webpackChunkName: "succedit" */ '../views/success-story/StoryEdit.vue') }, { path: '/success-story/view/:id', diff --git a/src/JobsJobsJobs/App/src/views/citizen/EditProfile.vue b/src/JobsJobsJobs/App/src/views/citizen/EditProfile.vue index 95423c0..3505b7c 100644 --- a/src/JobsJobsJobs/App/src/views/citizen/EditProfile.vue +++ b/src/JobsJobsJobs/App/src/views/citizen/EditProfile.vue @@ -17,8 +17,8 @@ -

- If you have found employment, consider telling your fellow +

+ If you have found employment, consider telling your fellow citizens about it!

diff --git a/src/JobsJobsJobs/App/src/views/profile/ProfileView.vue b/src/JobsJobsJobs/App/src/views/profile/ProfileView.vue index dcec510..dcf736c 100644 --- a/src/JobsJobsJobs/App/src/views/profile/ProfileView.vue +++ b/src/JobsJobsJobs/App/src/views/profile/ProfileView.vue @@ -3,14 +3,14 @@

{{citizenName}}

-

{{it.continent.name}}, {{it.profile.region}}

+

{{it.continent.name}}, {{it.profile.region}}