all repos — caroster @ c89a9ce0b73efca90a0c9c1821531d7232851c69

[Octree] Group carpool to your event https://caroster.io

add events to user
Hadrien Froger hadrien@octree.ch
Thu, 16 Jul 2020 15:01:47 +0100
commit

c89a9ce0b73efca90a0c9c1821531d7232851c69

parent

550370ebaa750b5433b92c35d407de6f7f363911

A .vscode/settings.json

@@ -0,0 +1,1 @@

+123,125
M app/package.jsonapp/package.json

@@ -4,7 +4,6 @@ "version": "0.1.0",

"private": true, "proxy": "http://localhost:1337", "dependencies": { - "@babel/runtime": "^7.10.5", "@date-io/moment": "^1.3.13", "@material-ui/core": "^4.10.2", "@material-ui/pickers": "^3.2.10",

@@ -12,7 +11,7 @@ "@testing-library/jest-dom": "^4.2.4",

"@testing-library/react": "^9.5.0", "@testing-library/user-event": "^7.2.1", "fontsource-roboto": "^2.1.4", - "i18next": "^19.6.1", + "i18next": "^19.5.1", "leaflet": "^1.6.0", "marked": "^1.1.0", "moment": "^2.27.0",

@@ -24,7 +23,7 @@ "react-leaflet": "^2.7.0",

"react-router-dom": "^5.2.0", "react-scripts": "3.4.1", "react-slick": "^0.26.1", - "strapi-react-context": "^0.2.4" + "strapi-react-context": "^0.2.3" }, "scripts": { "start": "react-scripts start",

@@ -49,8 +48,6 @@ "last 1 safari version"

] }, "devDependencies": { - "@babel/plugin-transform-runtime": "^7.10.5", - "eslint-config-google": "^0.14.0", - "react-test-renderer": "^16.13.1" + "eslint-config-google": "^0.14.0" } }
M app/src/App.jsapp/src/App.js

@@ -12,6 +12,7 @@ const models = [

{name: 'events'}, {name: 'cars'}, {name: 'pages'}, + {name: 'users'}, {name: 'settings', singleType: true, init: true}, ];
M app/src/containers/Car/index.jsapp/src/containers/Car/index.js

@@ -3,7 +3,7 @@ import {makeStyles} from '@material-ui/core/styles';

import Divider from '@material-ui/core/Divider'; import Paper from '@material-ui/core/Paper'; import {useTranslation} from 'react-i18next'; -import {useStrapi} from 'strapi-react-context'; +import {useStrapi, useAuth} from 'strapi-react-context'; import {useEvent} from '../../contexts/Event'; import {useToast} from '../../contexts/Toast'; import PassengersList from '../PassengersList';

@@ -16,6 +16,7 @@ const {t} = useTranslation();

const {event} = useEvent(); const {addToast} = useToast(); const strapi = useStrapi(); + const {token, authState} = useAuth(); const [isEditing, toggleEditing] = useReducer(i => !i, false); if (!car) return null;

@@ -25,9 +26,16 @@ try {

await strapi.services.cars.update(car.id, { passengers: [...(car.passengers || []), passenger], }); + if (!!token) { + const {user} = authState; + const {events = []} = user; + await strapi.services.users.update('me', { + ...user, + events: [...events.filter(e => e !== event.id), event.id], + }); + } } catch (error) { console.error(error); - addToast(t('car.errors.cant_add_passenger')); } };
M extensions/documentation/public/index.htmlextensions/documentation/public/index.html

@@ -33,7 +33,7 @@ <script class="custom-swagger-ui">

window.onload = function() { const ui = SwaggerUIBundle({ url: "https://petstore.swagger.io/v2/swagger.json", - spec: {"openapi":"3.0.0","info":{"version":"1.0.0","title":"Documentation de l'API Caroster","description":"","termsOfService":"YOUR_TERMS_OF_SERVICE_URL","contact":{"name":"Octree","email":"sysadmin@octree.ch","url":"octree.ch"},"license":{"name":"Apache 2.0","url":"https://www.apache.org/licenses/LICENSE-2.0.html"},"x-generation-date":"06/27/2020 6:41:02 PM"},"x-strapi-config":{"path":"/documentation","showGeneratedFiles":true,"generateDefaultResponse":true,"pluginsForWhichToGenerateDoc":[]},"servers":[{"url":"http://localhost:1337","description":"Development server"},{"url":"https://caroster.dev.octr.ee","description":"Test server"},{"url":"https://caroster.io","description":"Production server"}],"externalDocs":{"description":"Find out more","url":"https://strapi.io/documentation/"},"security":[{"bearerAuth":[]}],"paths":{"/cars":{"get":{"deprecated":false,"description":"","responses":{"200":{"description":"response","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Car"}}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Car"],"parameters":[{"name":"_limit","in":"query","required":false,"description":"Maximum number of results possible","schema":{"type":"integer"},"deprecated":false},{"name":"_sort","in":"query","required":false,"description":"Sort according to a specific field.","schema":{"type":"string"},"deprecated":false},{"name":"_start","in":"query","required":false,"description":"Skip a specific number of entries (especially useful for pagination)","schema":{"type":"integer"},"deprecated":false},{"name":"=","in":"query","required":false,"description":"Get entries that matches exactly your input","schema":{"type":"string"},"deprecated":false},{"name":"_ne","in":"query","required":false,"description":"Get records that are not equals to something","schema":{"type":"string"},"deprecated":false},{"name":"_lt","in":"query","required":false,"description":"Get record that are lower than a value","schema":{"type":"string"},"deprecated":false},{"name":"_lte","in":"query","required":false,"description":"Get records that are lower than or equal to a value","schema":{"type":"string"},"deprecated":false},{"name":"_gt","in":"query","required":false,"description":"Get records that are greater than a value","schema":{"type":"string"},"deprecated":false},{"name":"_gte","in":"query","required":false,"description":"Get records that are greater than or equal a value","schema":{"type":"string"},"deprecated":false},{"name":"_contains","in":"query","required":false,"description":"Get records that contains a value","schema":{"type":"string"},"deprecated":false},{"name":"_containss","in":"query","required":false,"description":"Get records that contains (case sensitive) a value","schema":{"type":"string"},"deprecated":false},{"name":"_in","in":"query","required":false,"description":"Get records that matches any value in the array of values","schema":{"type":"array","items":{"type":"string"}},"deprecated":false},{"name":"_nin","in":"query","required":false,"description":"Get records that doesn't match any value in the array of values","schema":{"type":"array","items":{"type":"string"}},"deprecated":false}]},"post":{"deprecated":false,"description":"Create a new record","responses":{"200":{"description":"response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Car"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Car"],"requestBody":{"description":"","required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/NewCar"}}}}}},"/cars/count":{"get":{"deprecated":false,"description":"","responses":{"200":{"description":"response","content":{"application/json":{"schema":{"properties":{"count":{"type":"integer"}}}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Car"],"parameters":[]}},"/cars/{id}":{"get":{"deprecated":false,"description":"","responses":{"200":{"description":"response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Car"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Car"],"parameters":[{"name":"id","in":"path","description":"","deprecated":false,"required":true,"schema":{"type":"string"}}]},"put":{"deprecated":false,"description":"Update a record","responses":{"200":{"description":"response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Car"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Car"],"requestBody":{"description":"","required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/NewCar"}}}},"parameters":[{"name":"id","in":"path","description":"","deprecated":false,"required":true,"schema":{"type":"string"}}]},"delete":{"deprecated":false,"description":"Delete a record","responses":{"200":{"description":"deletes a single record based on the ID supplied","content":{"application/json":{"schema":{"type":"integer","format":"int64"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Car"],"parameters":[{"name":"id","in":"path","description":"","deprecated":false,"required":true,"schema":{"type":"string"}}]}},"/events":{"get":{"deprecated":false,"description":"","responses":{"200":{"description":"response","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Event"}}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Event"],"parameters":[{"name":"_limit","in":"query","required":false,"description":"Maximum number of results possible","schema":{"type":"integer"},"deprecated":false},{"name":"_sort","in":"query","required":false,"description":"Sort according to a specific field.","schema":{"type":"string"},"deprecated":false},{"name":"_start","in":"query","required":false,"description":"Skip a specific number of entries (especially useful for pagination)","schema":{"type":"integer"},"deprecated":false},{"name":"=","in":"query","required":false,"description":"Get entries that matches exactly your input","schema":{"type":"string"},"deprecated":false},{"name":"_ne","in":"query","required":false,"description":"Get records that are not equals to something","schema":{"type":"string"},"deprecated":false},{"name":"_lt","in":"query","required":false,"description":"Get record that are lower than a value","schema":{"type":"string"},"deprecated":false},{"name":"_lte","in":"query","required":false,"description":"Get records that are lower than or equal to a value","schema":{"type":"string"},"deprecated":false},{"name":"_gt","in":"query","required":false,"description":"Get records that are greater than a value","schema":{"type":"string"},"deprecated":false},{"name":"_gte","in":"query","required":false,"description":"Get records that are greater than or equal a value","schema":{"type":"string"},"deprecated":false},{"name":"_contains","in":"query","required":false,"description":"Get records that contains a value","schema":{"type":"string"},"deprecated":false},{"name":"_containss","in":"query","required":false,"description":"Get records that contains (case sensitive) a value","schema":{"type":"string"},"deprecated":false},{"name":"_in","in":"query","required":false,"description":"Get records that matches any value in the array of values","schema":{"type":"array","items":{"type":"string"}},"deprecated":false},{"name":"_nin","in":"query","required":false,"description":"Get records that doesn't match any value in the array of values","schema":{"type":"array","items":{"type":"string"}},"deprecated":false}]},"post":{"deprecated":false,"description":"Create a new record","responses":{"200":{"description":"response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Event"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Event"],"requestBody":{"description":"","required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/NewEvent"}}}}}},"/events/count":{"get":{"deprecated":false,"description":"","responses":{"200":{"description":"response","content":{"application/json":{"schema":{"properties":{"count":{"type":"integer"}}}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Event"],"parameters":[]}},"/events/{id}":{"get":{"deprecated":false,"description":"","responses":{"200":{"description":"response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Event"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Event"],"parameters":[{"name":"id","in":"path","description":"","deprecated":false,"required":true,"schema":{"type":"string"}}]},"put":{"deprecated":false,"description":"Update a record","responses":{"200":{"description":"response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Event"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Event"],"requestBody":{"description":"","required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/NewEvent"}}}},"parameters":[{"name":"id","in":"path","description":"","deprecated":false,"required":true,"schema":{"type":"string"}}]},"delete":{"deprecated":false,"description":"Delete a record","responses":{"200":{"description":"deletes a single record based on the ID supplied","content":{"application/json":{"schema":{"type":"integer","format":"int64"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Event"],"parameters":[{"name":"id","in":"path","description":"","deprecated":false,"required":true,"schema":{"type":"string"}}]}}},"components":{"schemas":{"Car":{"required":["id","name","seats"],"properties":{"id":{"type":"string"},"name":{"type":"string"},"seats":{"type":"integer"},"meeting":{"type":"string"},"departure":{"type":"datetime"},"phone_number":{"type":"string"},"details":{"type":"string"}}},"NewCar":{"required":["name","seats"],"properties":{"name":{"type":"string"},"seats":{"type":"integer"},"meeting":{"type":"string"},"departure":{"type":"datetime"},"phone_number":{"type":"string"},"details":{"type":"string"}}},"Event":{"required":["id","name","email"],"properties":{"id":{"type":"string"},"name":{"type":"string"},"email":{"type":"string"},"date":{"type":"string"},"address":{"type":"string"}}},"NewEvent":{"required":["name","email"],"properties":{"name":{"type":"string"},"email":{"type":"string"},"date":{"type":"string"},"address":{"type":"string"}}},"Error":{"required":["code","message"],"properties":{"code":{"type":"integer","format":"int32"},"message":{"type":"string"}}}},"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}}},"tags":[{"name":"Car"},{"name":"Event"}]}, + spec: {"openapi":"3.0.0","info":{"version":"1.0.0","title":"Documentation de l'API Caroster","description":"","termsOfService":"YOUR_TERMS_OF_SERVICE_URL","contact":{"name":"Octree","email":"sysadmin@octree.ch","url":"octree.ch"},"license":{"name":"Apache 2.0","url":"https://www.apache.org/licenses/LICENSE-2.0.html"},"x-generation-date":"07/08/2020 12:13:00 PM"},"x-strapi-config":{"path":"/documentation","showGeneratedFiles":true,"generateDefaultResponse":true,"pluginsForWhichToGenerateDoc":[]},"servers":[{"url":"http://localhost:1337","description":"Development server"},{"url":"https://caroster.dev.octr.ee","description":"Test server"},{"url":"https://caroster.io","description":"Production server"}],"externalDocs":{"description":"Find out more","url":"https://strapi.io/documentation/"},"security":[{"bearerAuth":[]}],"paths":{"/cars":{"get":{"deprecated":false,"description":"","responses":{"200":{"description":"response","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Car"}}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Car"],"parameters":[{"name":"_limit","in":"query","required":false,"description":"Maximum number of results possible","schema":{"type":"integer"},"deprecated":false},{"name":"_sort","in":"query","required":false,"description":"Sort according to a specific field.","schema":{"type":"string"},"deprecated":false},{"name":"_start","in":"query","required":false,"description":"Skip a specific number of entries (especially useful for pagination)","schema":{"type":"integer"},"deprecated":false},{"name":"=","in":"query","required":false,"description":"Get entries that matches exactly your input","schema":{"type":"string"},"deprecated":false},{"name":"_ne","in":"query","required":false,"description":"Get records that are not equals to something","schema":{"type":"string"},"deprecated":false},{"name":"_lt","in":"query","required":false,"description":"Get record that are lower than a value","schema":{"type":"string"},"deprecated":false},{"name":"_lte","in":"query","required":false,"description":"Get records that are lower than or equal to a value","schema":{"type":"string"},"deprecated":false},{"name":"_gt","in":"query","required":false,"description":"Get records that are greater than a value","schema":{"type":"string"},"deprecated":false},{"name":"_gte","in":"query","required":false,"description":"Get records that are greater than or equal a value","schema":{"type":"string"},"deprecated":false},{"name":"_contains","in":"query","required":false,"description":"Get records that contains a value","schema":{"type":"string"},"deprecated":false},{"name":"_containss","in":"query","required":false,"description":"Get records that contains (case sensitive) a value","schema":{"type":"string"},"deprecated":false},{"name":"_in","in":"query","required":false,"description":"Get records that matches any value in the array of values","schema":{"type":"array","items":{"type":"string"}},"deprecated":false},{"name":"_nin","in":"query","required":false,"description":"Get records that doesn't match any value in the array of values","schema":{"type":"array","items":{"type":"string"}},"deprecated":false}]},"post":{"deprecated":false,"description":"Create a new record","responses":{"200":{"description":"response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Car"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Car"],"requestBody":{"description":"","required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/NewCar"}}}}}},"/cars/count":{"get":{"deprecated":false,"description":"","responses":{"200":{"description":"response","content":{"application/json":{"schema":{"properties":{"count":{"type":"integer"}}}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Car"],"parameters":[]}},"/cars/{id}":{"get":{"deprecated":false,"description":"","responses":{"200":{"description":"response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Car"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Car"],"parameters":[{"name":"id","in":"path","description":"","deprecated":false,"required":true,"schema":{"type":"string"}}]},"put":{"deprecated":false,"description":"Update a record","responses":{"200":{"description":"response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Car"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Car"],"requestBody":{"description":"","required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/NewCar"}}}},"parameters":[{"name":"id","in":"path","description":"","deprecated":false,"required":true,"schema":{"type":"string"}}]},"delete":{"deprecated":false,"description":"Delete a record","responses":{"200":{"description":"deletes a single record based on the ID supplied","content":{"application/json":{"schema":{"type":"integer","format":"int64"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Car"],"parameters":[{"name":"id","in":"path","description":"","deprecated":false,"required":true,"schema":{"type":"string"}}]}},"/events":{"get":{"deprecated":false,"description":"","responses":{"200":{"description":"response","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Event"}}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Event"],"parameters":[{"name":"_limit","in":"query","required":false,"description":"Maximum number of results possible","schema":{"type":"integer"},"deprecated":false},{"name":"_sort","in":"query","required":false,"description":"Sort according to a specific field.","schema":{"type":"string"},"deprecated":false},{"name":"_start","in":"query","required":false,"description":"Skip a specific number of entries (especially useful for pagination)","schema":{"type":"integer"},"deprecated":false},{"name":"=","in":"query","required":false,"description":"Get entries that matches exactly your input","schema":{"type":"string"},"deprecated":false},{"name":"_ne","in":"query","required":false,"description":"Get records that are not equals to something","schema":{"type":"string"},"deprecated":false},{"name":"_lt","in":"query","required":false,"description":"Get record that are lower than a value","schema":{"type":"string"},"deprecated":false},{"name":"_lte","in":"query","required":false,"description":"Get records that are lower than or equal to a value","schema":{"type":"string"},"deprecated":false},{"name":"_gt","in":"query","required":false,"description":"Get records that are greater than a value","schema":{"type":"string"},"deprecated":false},{"name":"_gte","in":"query","required":false,"description":"Get records that are greater than or equal a value","schema":{"type":"string"},"deprecated":false},{"name":"_contains","in":"query","required":false,"description":"Get records that contains a value","schema":{"type":"string"},"deprecated":false},{"name":"_containss","in":"query","required":false,"description":"Get records that contains (case sensitive) a value","schema":{"type":"string"},"deprecated":false},{"name":"_in","in":"query","required":false,"description":"Get records that matches any value in the array of values","schema":{"type":"array","items":{"type":"string"}},"deprecated":false},{"name":"_nin","in":"query","required":false,"description":"Get records that doesn't match any value in the array of values","schema":{"type":"array","items":{"type":"string"}},"deprecated":false}]},"post":{"deprecated":false,"description":"Create a new record","responses":{"200":{"description":"response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Event"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Event"],"requestBody":{"description":"","required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/NewEvent"}}}}}},"/events/count":{"get":{"deprecated":false,"description":"","responses":{"200":{"description":"response","content":{"application/json":{"schema":{"properties":{"count":{"type":"integer"}}}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Event"],"parameters":[]}},"/events/{id}":{"get":{"deprecated":false,"description":"","responses":{"200":{"description":"response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Event"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Event"],"parameters":[{"name":"id","in":"path","description":"","deprecated":false,"required":true,"schema":{"type":"string"}}]},"put":{"deprecated":false,"description":"Update a record","responses":{"200":{"description":"response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Event"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Event"],"requestBody":{"description":"","required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/NewEvent"}}}},"parameters":[{"name":"id","in":"path","description":"","deprecated":false,"required":true,"schema":{"type":"string"}}]},"delete":{"deprecated":false,"description":"Delete a record","responses":{"200":{"description":"deletes a single record based on the ID supplied","content":{"application/json":{"schema":{"type":"integer","format":"int64"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Event"],"parameters":[{"name":"id","in":"path","description":"","deprecated":false,"required":true,"schema":{"type":"string"}}]}},"/pages":{"get":{"deprecated":false,"description":"","responses":{"200":{"description":"response","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Page"}}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Page"],"parameters":[{"name":"_limit","in":"query","required":false,"description":"Maximum number of results possible","schema":{"type":"integer"},"deprecated":false},{"name":"_sort","in":"query","required":false,"description":"Sort according to a specific field.","schema":{"type":"string"},"deprecated":false},{"name":"_start","in":"query","required":false,"description":"Skip a specific number of entries (especially useful for pagination)","schema":{"type":"integer"},"deprecated":false},{"name":"=","in":"query","required":false,"description":"Get entries that matches exactly your input","schema":{"type":"string"},"deprecated":false},{"name":"_ne","in":"query","required":false,"description":"Get records that are not equals to something","schema":{"type":"string"},"deprecated":false},{"name":"_lt","in":"query","required":false,"description":"Get record that are lower than a value","schema":{"type":"string"},"deprecated":false},{"name":"_lte","in":"query","required":false,"description":"Get records that are lower than or equal to a value","schema":{"type":"string"},"deprecated":false},{"name":"_gt","in":"query","required":false,"description":"Get records that are greater than a value","schema":{"type":"string"},"deprecated":false},{"name":"_gte","in":"query","required":false,"description":"Get records that are greater than or equal a value","schema":{"type":"string"},"deprecated":false},{"name":"_contains","in":"query","required":false,"description":"Get records that contains a value","schema":{"type":"string"},"deprecated":false},{"name":"_containss","in":"query","required":false,"description":"Get records that contains (case sensitive) a value","schema":{"type":"string"},"deprecated":false},{"name":"_in","in":"query","required":false,"description":"Get records that matches any value in the array of values","schema":{"type":"array","items":{"type":"string"}},"deprecated":false},{"name":"_nin","in":"query","required":false,"description":"Get records that doesn't match any value in the array of values","schema":{"type":"array","items":{"type":"string"}},"deprecated":false}]},"post":{"deprecated":false,"description":"Create a new record","responses":{"200":{"description":"response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Page"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Page"],"requestBody":{"description":"","required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/NewPage"}}}}}},"/pages/count":{"get":{"deprecated":false,"description":"","responses":{"200":{"description":"response","content":{"application/json":{"schema":{"properties":{"count":{"type":"integer"}}}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Page"],"parameters":[]}},"/pages/{id}":{"get":{"deprecated":false,"description":"","responses":{"200":{"description":"response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Page"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Page"],"parameters":[{"name":"id","in":"path","description":"","deprecated":false,"required":true,"schema":{"type":"string"}}]},"put":{"deprecated":false,"description":"Update a record","responses":{"200":{"description":"response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Page"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Page"],"requestBody":{"description":"","required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/NewPage"}}}},"parameters":[{"name":"id","in":"path","description":"","deprecated":false,"required":true,"schema":{"type":"string"}}]},"delete":{"deprecated":false,"description":"Delete a record","responses":{"200":{"description":"deletes a single record based on the ID supplied","content":{"application/json":{"schema":{"type":"integer","format":"int64"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Page"],"parameters":[{"name":"id","in":"path","description":"","deprecated":false,"required":true,"schema":{"type":"string"}}]}},"/settings":{"get":{"deprecated":false,"description":"Find all the settings's records","responses":{"200":{"description":"Retrieve settings document(s)","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Settings"}}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Settings"],"parameters":[{"name":"_limit","in":"query","required":false,"description":"Maximum number of results possible","schema":{"type":"integer"},"deprecated":false},{"name":"_sort","in":"query","required":false,"description":"Sort according to a specific field.","schema":{"type":"string"},"deprecated":false},{"name":"_start","in":"query","required":false,"description":"Skip a specific number of entries (especially useful for pagination)","schema":{"type":"integer"},"deprecated":false},{"name":"=","in":"query","required":false,"description":"Get entries that matches exactly your input","schema":{"type":"string"},"deprecated":false},{"name":"_ne","in":"query","required":false,"description":"Get records that are not equals to something","schema":{"type":"string"},"deprecated":false},{"name":"_lt","in":"query","required":false,"description":"Get record that are lower than a value","schema":{"type":"string"},"deprecated":false},{"name":"_lte","in":"query","required":false,"description":"Get records that are lower than or equal to a value","schema":{"type":"string"},"deprecated":false},{"name":"_gt","in":"query","required":false,"description":"Get records that are greater than a value","schema":{"type":"string"},"deprecated":false},{"name":"_gte","in":"query","required":false,"description":"Get records that are greater than or equal a value","schema":{"type":"string"},"deprecated":false},{"name":"_contains","in":"query","required":false,"description":"Get records that contains a value","schema":{"type":"string"},"deprecated":false},{"name":"_containss","in":"query","required":false,"description":"Get records that contains (case sensitive) a value","schema":{"type":"string"},"deprecated":false},{"name":"_in","in":"query","required":false,"description":"Get records that matches any value in the array of values","schema":{"type":"array","items":{"type":"string"}},"deprecated":false},{"name":"_nin","in":"query","required":false,"description":"Get records that doesn't match any value in the array of values","schema":{"type":"array","items":{"type":"string"}},"deprecated":false}]},"put":{"deprecated":false,"description":"Update a single settings record","responses":{"200":{"description":"Retrieve settings document(s)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Settings"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Settings"],"requestBody":{"description":"","required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/NewSettings"}}}},"parameters":[]},"delete":{"deprecated":false,"description":"Delete a single settings record","responses":{"200":{"description":"deletes a single settings based on the ID supplied","content":{"application/json":{"schema":{"type":"integer","format":"int64"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"summary":"","tags":["Settings"],"parameters":[]}}},"components":{"schemas":{"Car":{"required":["id","name","seats"],"properties":{"id":{"type":"string"},"name":{"type":"string"},"seats":{"type":"integer"},"meeting":{"type":"string"},"departure":{"type":"datetime"},"phone_number":{"type":"string"},"details":{"type":"string"},"event":{"required":["id","name","email"],"properties":{"id":{"type":"string"},"name":{"type":"string"},"email":{"type":"string"},"date":{"type":"string"},"address":{"type":"string"},"cars":{"type":"array","items":{"type":"string"}},"position":{"type":"object"},"waiting_list":{"type":"object"}}},"passengers":{"type":"object"}}},"NewCar":{"required":["name","seats"],"properties":{"name":{"type":"string"},"seats":{"type":"integer"},"meeting":{"type":"string"},"departure":{"type":"datetime"},"phone_number":{"type":"string"},"details":{"type":"string"},"event":{"type":"string"},"passengers":{"type":"object"}}},"Event":{"required":["id","name","email"],"properties":{"id":{"type":"string"},"name":{"type":"string"},"email":{"type":"string"},"date":{"type":"string"},"address":{"type":"string"},"cars":{"type":"array","items":{"required":["id","name","seats"],"properties":{"id":{"type":"string"},"name":{"type":"string"},"seats":{"type":"integer"},"meeting":{"type":"string"},"departure":{"type":"datetime"},"phone_number":{"type":"string"},"details":{"type":"string"},"event":{"type":"string"},"passengers":{"type":"object"}}}},"position":{"type":"object"},"waiting_list":{"type":"object"}}},"NewEvent":{"required":["name","email"],"properties":{"name":{"type":"string"},"email":{"type":"string"},"date":{"type":"string"},"address":{"type":"string"},"cars":{"type":"array","items":{"type":"string"}},"position":{"type":"object"},"waiting_list":{"type":"object"}}},"Page":{"required":["id","name"],"properties":{"id":{"type":"string"},"name":{"type":"string"},"content":{"type":"string"},"type":{"type":"string","enum":["tos"]}}},"NewPage":{"required":["name"],"properties":{"name":{"type":"string"},"content":{"type":"string"},"type":{"type":"string","enum":["tos"]}}},"Settings":{"required":["id"],"properties":{"id":{"type":"string"},"gtm_id":{"type":"string"}}},"NewSettings":{"properties":{"gtm_id":{"type":"string"}}},"Error":{"required":["code","message"],"properties":{"code":{"type":"integer","format":"int32"},"message":{"type":"string"}}}},"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}}},"tags":[{"name":"Car"},{"name":"Event"},{"name":"Page"},{"name":"Settings"}]}, dom_id: '#swagger-ui', docExpansion: "none", deepLinking: true,
A extensions/users-permissions/config/policies/setMe.js

@@ -0,0 +1,6 @@

+// Set authenticated user ID as queried ID +module.exports = async (ctx, next) => { + ctx.params.id = ctx.state.user.id; + console.log('USER ID', ctx.state.user.id); + await next(); +};
A extensions/users-permissions/config/routes.json

@@ -0,0 +1,20 @@

+{ + "routes": [ + { + "method": "PUT", + "path": "/users/me", + "handler": "CarosterUser.update", + + "config": { + "policies": ["plugins::users-permissions.setme"], + "prefix": "", + "description": "Update an existing user", + "tag": { + "plugin": "users-permissions", + "name": "User", + "actionType": "update" + } + } + } + ] +}
A extensions/users-permissions/controllers/CarosterUser.js

@@ -0,0 +1,111 @@

+const _ = require('lodash'); + +module.exports = { + /** + * Update a record. + * + * @return {Object} + */ + update: async ctx => { + console.log('I AM HEREE'); + const advancedConfigs = await strapi + .store({ + environment: '', + type: 'plugin', + name: 'users-permissions', + key: 'advanced', + }) + .get(); + + const {id} = ctx.params; + const { + email, + username, + password, + firstName, + lastName, + events = [], + } = ctx.request.body; + + const user = await strapi.plugins['users-permissions'].services.user.fetch({ + id, + }); + + if (_.has(ctx.request.body, 'email') && !email) { + return ctx.badRequest('email.notNull'); + } + + if (_.has(ctx.request.body, 'firstName') && !firstName) { + return ctx.badRequest('firstName.notNull'); + } + + if (_.has(ctx.request.body, 'lastName') && !lastName) { + return ctx.badRequest('lastName.notNull'); + } + + if (_.has(ctx.request.body, 'username') && !username) { + return ctx.badRequest('username.notNull'); + } + + if ( + _.has(ctx.request.body, 'password') && + !password && + user.provider === 'local' + ) { + return ctx.badRequest('password.notNull'); + } + + if (_.has(ctx.request.body, 'username')) { + const userWithSameUsername = await strapi + .query('user', 'users-permissions') + .findOne({username}); + + if (userWithSameUsername && userWithSameUsername.id != id) { + return ctx.badRequest( + null, + formatError({ + id: 'Auth.form.error.username.taken', + message: 'username.alreadyTaken.', + field: ['username'], + }) + ); + } + } + + if (_.has(ctx.request.body, 'email') && advancedConfigs.unique_email) { + const userWithSameEmail = await strapi + .query('user', 'users-permissions') + .findOne({email}); + + if (userWithSameEmail && userWithSameEmail.id != id) { + return ctx.badRequest( + null, + formatError({ + id: 'Auth.form.error.email.taken', + message: 'Email already taken', + field: ['email'], + }) + ); + } + } + + let updateData = { + ...ctx.request.body, + }; + + if (_.has(ctx.request.body, 'password') && password === user.password) { + delete updateData.password; + } + + if (!_.has(ctx.request.body, 'events')) { + updateData.events = []; + } + + const data = await strapi.plugins['users-permissions'].services.user.edit( + {id}, + updateData + ); + + ctx.send({...data}); + }, +};
M extensions/users-permissions/models/User.settings.jsonextensions/users-permissions/models/User.settings.json

@@ -1,65 +1,73 @@

{ - "connection": "default", - "info": { - "name": "user", - "description": "" + "kind": "collectionType", + "connection": "default", + "collectionName": "users-permissions_user", + "info": { + "name": "user", + "description": "" + }, + "options": { + "timestamps": true + }, + "attributes": { + "username": { + "type": "string", + "minLength": 3, + "unique": true, + "configurable": false, + "required": true }, - "attributes": { - "username": { - "type": "string", - "minLength": 3, - "unique": true, - "configurable": false, - "required": true - }, - "firstName": { - "type": "string", - "minLength": 3, - "configurable": false, - "required": true - }, - "lastName": { - "type": "string", - "minLength": 3, - "configurable": false, - "required": true - }, - "email": { - "type": "email", - "minLength": 6, - "configurable": false, - "required": true - }, - "provider": { - "type": "string", - "configurable": false - }, - "password": { - "type": "password", - "minLength": 6, - "configurable": false, - "private": true - }, - "resetPasswordToken": { - "type": "string", - "configurable": false, - "private": true - }, - "confirmed": { - "type": "boolean", - "default": false, - "configurable": false - }, - "blocked": { - "type": "boolean", - "default": false, - "configurable": false - }, - "role": { - "model": "role", - "via": "users", - "plugin": "users-permissions", - "configurable": false - } + "firstName": { + "type": "string", + "minLength": 3, + "configurable": false, + "required": true + }, + "lastName": { + "type": "string", + "minLength": 3, + "configurable": false, + "required": true + }, + "email": { + "type": "email", + "minLength": 6, + "configurable": false, + "required": true + }, + "provider": { + "type": "string", + "configurable": false + }, + "password": { + "type": "password", + "minLength": 6, + "configurable": false, + "private": true + }, + "resetPasswordToken": { + "type": "string", + "configurable": false, + "private": true + }, + "confirmed": { + "type": "boolean", + "default": false, + "configurable": false + }, + "blocked": { + "type": "boolean", + "default": false, + "configurable": false + }, + "role": { + "model": "role", + "via": "users", + "plugin": "users-permissions", + "configurable": false + }, + "events": { + "type": "json" } - }+ } +}