Skip to content

Commit

Permalink
ref(ory): use schema Citizens Schema v0.3.4 (#63)
Browse files Browse the repository at this point in the history
* ref(ory): use schema `Citizens Schema v0.2.0`

* fix(api): add firstname

* fix(ory): correct schema adaptations

* fix(schema): `emails` is an array

* fix(schema): firstName is name

* fix(schema): revert email array

* ref(ory): adapting props to `Schema v0.3.4`

---------

Co-authored-by: Marluan Espiritusanto <[email protected]>
  • Loading branch information
gustavovalverde and marluanespiritusanto authored Jul 28, 2023
1 parent 20112c7 commit cbff3b4
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 18 deletions.
4 changes: 3 additions & 1 deletion src/common/interfaces/citizen-complete-data.interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export interface CitizenCompleteData {
id: string;
name: string;
names: string;
firstSurname: string;
secondSurname: string;
gender: string;
birthDate: string;
}
10 changes: 5 additions & 5 deletions src/constants/messages.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
export const CREATE_BROWSER_REGISTRATION_FLOW_ERROR =
'¡Ups! Ha ocurrido un error, favor intentarlo más tarde.';
'¡Ups! Ha ocurrido un error, por favor inténtelo más tarde.';
export const INVALID_CEDULA_ERROR =
'Al parecer ha introducido una cédula inválida';
export const IDENTITY_ALREADY_EXISTS_ERROR =
'Esta cédula ya ha sido registrada.';
export const INVALID_CEDULA_NUMBER_ERROR =
'Al parecer ha introducido una numeración de cédula inválida';
export const RECAPTCHA_ISSUES_ERROR =
'Al parecer el reCaptcha no ha validado correctamente su solicitud, intente nuevamente más tarde';
'Al parecer el reCaptcha no ha validado correctamente su solicitud, refresque e intente nuevamente';
export const RECAPTCHA_VALIDATION_ERROR =
'No podemos validar si eres un humano, intenta desde otro navegador o dispositivo.';
'No podemos validar la seguridad de su navegador, verifique si tiene actualizaciones pendientes o intente con otro dispositivo.';
export const VALIDATE_PASSWORD_ERROR =
'Al parecer ha ocurrido un error al intentar validar su contraseña, inténtelo de nuevo más tarde.';
export const CREATE_IDENTITY_ERROR =
'Ha ocurrido un error intentando crear la cuenta del ciudadano. Por favor, inténtelo más tarde.';
'Ha ocurrido un error intentando crear la cuenta ciudadana. Por favor, inténtelo más tarde.';
export const NON_ACCEPTED_TERMS_AND_CONDS_ERROR =
'Para continuar, se deben leer y aceptar los términos y políticas de privacidad.';
'Para continuar, debe leer y aceptar los términos y políticas de privacidad.';
35 changes: 28 additions & 7 deletions src/pages/api/citizens/[cedula].ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ import axios from 'axios';

import {
CitizensBasicInformationResponse,
CitizensBirthInformationResponse,
CitizensTokenResponse,
} from '../types';

export default async function handler(
req: NextApiRequest,
res: NextApiResponse<{
name: string;
id: string;
name?: string;
names?: string;
firstSurname?: string;
secondSurname?: string;
gender?: string;
birthDate?: string;
} | void>
): Promise<void> {
const { token } = req.cookies;
Expand Down Expand Up @@ -49,15 +53,32 @@ export default async function handler(
}
);

const { names, id, firstSurname, secondSurname } = citizen.payload;
const { names, id, firstSurname, secondSurname, gender } = citizen.payload;
const name = names.split(' ')[0];

if (validated) {
return res
.status(200)
.json({ name: names, id, firstSurname, secondSurname });
}
const { data: citizensBirthData } =
await http.get<CitizensBirthInformationResponse>(
`/${cedula}/info/birth?api-key=${process.env.CEDULA_API_KEY}`,
{
headers: {
Authorization: `Bearer ${citizensToken.access_token}`,
},
}
);

const name = names.split(' ')[0];
let { birthDate } = citizensBirthData.payload;
birthDate = birthDate.split('T')[0];

return res.status(200).json({
names,
id,
firstSurname,
secondSurname,
gender,
birthDate,
});
}

return res.status(200).json({ name, id });
}
11 changes: 11 additions & 0 deletions src/pages/api/types/citizens.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@ export type CitizenBasicInformation = {
secondSurname: string;
gender: 'M' | 'F';
};
export type CitizenBirthInformation = {
id: string;
birthPlace: string;
birthDate: string;
nationality: string;
};

export type CitizensBasicInformationResponse = {
valid: boolean;
payload: CitizenBasicInformation;
};

export type CitizensBirthInformationResponse = {
valid: boolean;
payload: CitizenBirthInformation;
};

export type CitizensTokenResponse = {
access_token: string;
token_type: string;
Expand Down
18 changes: 16 additions & 2 deletions src/pages/api/types/iam.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface Identity {
traits: Traits;
verifiable_addresses: VerifiableAddress[];
recovery_addresses: RecoveryAddress[];
metadata_public: any;
metadata_public: MetadataPublic;
metadata_admin: any;
created_at: string;
updated_at: string;
Expand Down Expand Up @@ -37,9 +37,23 @@ export interface Webauthn {

export interface Traits {
cedula: string;
shortName: shortName;
email: string;
phone: string;
}

export interface shortName {
firstName: string;
lastName: string;
firstSurname: string;
}

export interface MetadataPublic {
fullName: fullName;
}

export interface fullName {
givenName: string;
surname: string;
}

export interface VerifiableAddress {
Expand Down
2 changes: 2 additions & 0 deletions src/pages/api/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export type {
CitizenBasicInformation,
CitizensBasicInformationResponse,
CitizensTokenResponse,
CitizenBirthInformation,
CitizensBirthInformationResponse,
} from './citizens.type';
export type { Identity } from './iam.type';
export type { ReCaptchaResponse } from './recaptcha.type';
10 changes: 7 additions & 3 deletions src/pages/register/stepper/step3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export default function Step3({ handleNext, infoCedula }: any) {
(n: any) => n.attributes['name'] === 'csrf_token'
);
const csrf_token = node?.attributes.value as string;
const lastName = `${citizen.firstSurname} ${citizen.secondSurname}`;
const surname = `${citizen.firstSurname} ${citizen.secondSurname}`;
const method = 'password';

const updateRegistrationFlowBody: UpdateRegistrationFlowBody = {
Expand All @@ -136,8 +136,12 @@ export default function Step3({ handleNext, infoCedula }: any) {
traits: {
email: form.email,
cedula: citizen.id,
firstName: citizen.name,
lastName,
fullName: {
givenName: citizen.names,
surname,
},
birthDate: citizen.birthDate,
gender: citizen.gender,
},
};

Expand Down

0 comments on commit cbff3b4

Please sign in to comment.