1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-18 07:52:23 +01:00

(feat) OpenAPI/users: gender, organization, address

This commit is contained in:
Sylvain 2022-12-07 12:56:35 +01:00
parent dcaa5ad28c
commit fdddb545d9
6 changed files with 36 additions and 8 deletions

View File

@ -5,6 +5,7 @@
- OpenAPI endpoint to fetch accounting data
- Updated OpenAPI documentation
- OpenAPI users endpoint offer ability to filter by created_after
- OpenAPI users endpoint return gender, organization and address
- Fix a bug: providing an array of attributes to filter OpenApi data, results in error
- Fix a bug: unable to manage stocks on new products
- Fix a bug: unsupported param[] syntax in OpenAPI

View File

@ -28,6 +28,9 @@ class OpenAPI::V1::UsersDoc < OpenAPI::V1::BaseDoc
"created_at": "2016-05-04T17:21:48.403+02:00",
"external_id": "J5821-4"
"full_name": "xxxx xxxx",
"gender": "man",
"organization": true,
"address": "2 impasse xxxxxx, BRUXELLES",
"group": {
"id": 1,
"name": "standard, association",
@ -40,6 +43,9 @@ class OpenAPI::V1::UsersDoc < OpenAPI::V1::BaseDoc
"created_at": "2016-05-03T15:21:13.125+02:00",
"external_id": "J5846-4"
"full_name": "xxxxx xxxxx",
"gender": "woman",
"organization": true,
"address": "Grenoble",
"group": {
"id": 2,
"name": "étudiant, - de 25 ans, enseignant, demandeur d'emploi",
@ -52,6 +58,9 @@ class OpenAPI::V1::UsersDoc < OpenAPI::V1::BaseDoc
"created_at": "2016-05-03T13:51:03.223+02:00",
"external_id": "J5900-1"
"full_name": "xxxxxxx xxxx",
"gender": "man",
"organization": false,
"address": "21 rue des xxxxxx",
"group": {
"id": 1,
"name": "standard, association",
@ -64,6 +73,9 @@ class OpenAPI::V1::UsersDoc < OpenAPI::V1::BaseDoc
"created_at": "2016-05-03T12:24:38.724+02:00",
"external_id": "P4172-4"
"full_name": "xxx xxxxxxx",
"gender": "woman",
"organization": false,
"address": "147 rue xxxxxx, 75000 PARIS, France",
"group": {
"id": 1,
"name": "standard, association",
@ -82,6 +94,9 @@ class OpenAPI::V1::UsersDoc < OpenAPI::V1::BaseDoc
"created_at": "2016-05-04T17:21:48.403+02:00",
"external_id": "J5500-4"
"full_name": "xxxx xxxxxx",
"gender": "man",
"organization": true,
"address": "38100",
"group": {
"id": 1,
"name": "standard, association",
@ -94,6 +109,9 @@ class OpenAPI::V1::UsersDoc < OpenAPI::V1::BaseDoc
"created_at": "2016-05-03T15:21:13.125+02:00",
"external_id": null,
"full_name": "xxxxx xxxxxx",
"gender": "woman",
"organization": true,
"address": "",
"group": {
"id": 2,
"name": "étudiant, - de 25 ans, enseignant, demandeur d'emploi",

View File

@ -33,4 +33,14 @@ class InvoicingProfile < ApplicationRecord
# if first_name or last_name is nil, the empty string will be used as a temporary replacement
"#{(first_name || '').humanize.titleize} #{(last_name || '').humanize.titleize}"
end
def invoicing_address
if organization&.address
organization.address.address
elsif address
address.address
else
''
end
end
end

View File

@ -18,13 +18,7 @@ class Invoices::RecipientService
# Get the street address of the recipient for the given invoice.
def address(invoice)
if invoice.invoicing_profile&.organization&.address
invoice.invoicing_profile.organization.address.address
elsif invoice.invoicing_profile&.address
invoice.invoicing_profile.address.address
else
''
end
invoice.invoicing_profile&.invoicing_address
end
# Get the optional data in profile_custom_fields, if the recipient is an organization

View File

@ -1,8 +1,10 @@
# frozen_string_literal: true
json.extract! user, :id, :email, :created_at, :external_id
json.full_name user.profile.full_name if user.association(:profile).loaded?
json.gender user.statistic_profile.gender ? 'man' : 'woman'
json.organization !user.invoicing_profile.organization.nil?
json.address user.invoicing_profile.invoicing_address
if user.association(:group).loaded?
json.group do

View File

@ -17,6 +17,9 @@ class OpenApi::UsersTest < ActionDispatch::IntegrationTest
users = json_response(response.body)
assert_equal User.count, users[:users].length
assert_not_nil(users[:users].detect { |u| u[:external_id] == 'J5821-4' })
assert(users[:users].all? { |u| %w[man woman].include?(u[:gender]) })
assert(users[:users].all? { |u| u[:organization] != User.find(u[:id]).invoicing_profile.organization.nil? })
assert(users[:users].any? { |u| u[:address].present? })
end
test 'list all users with pagination' do