[FEAT]: implement repository of create account
This commit is contained in:
parent
c0de160c59
commit
4e18835297
@ -16,6 +16,11 @@ class UsersModel {
|
||||
getTitle(): string {
|
||||
return this.modelTitle;
|
||||
}
|
||||
|
||||
addUser(user: Users): Users[] {
|
||||
this.usersList.push(user);
|
||||
return this.usersList;
|
||||
}
|
||||
}
|
||||
|
||||
export default UsersModel;
|
||||
|
@ -0,0 +1,12 @@
|
||||
import { CreateAccountDTOReturnType, INewUserDTO } from './protocols';
|
||||
|
||||
const createAccountDTO = (
|
||||
newUser: INewUserDTO
|
||||
): CreateAccountDTOReturnType => ({
|
||||
enabled: true,
|
||||
firstName: newUser.firstname,
|
||||
lastName: newUser.lastname,
|
||||
username: newUser.phonenumber,
|
||||
});
|
||||
|
||||
export default createAccountDTO;
|
@ -0,0 +1,12 @@
|
||||
export interface INewUserDTO {
|
||||
firstname: string;
|
||||
lastname: string;
|
||||
phonenumber: string;
|
||||
}
|
||||
|
||||
export type CreateAccountDTOReturnType = {
|
||||
username: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
enabled: true;
|
||||
};
|
@ -0,0 +1,8 @@
|
||||
import { INewUserDTO } from '../dto/protocols';
|
||||
import { CreateAccountROReturnType } from '../response-object/protocols';
|
||||
|
||||
interface ICreateAcountRepo {
|
||||
execute: (newUser: INewUserDTO) => Promise<CreateAccountROReturnType>;
|
||||
}
|
||||
|
||||
export default ICreateAcountRepo;
|
@ -0,0 +1,25 @@
|
||||
import createAccountDTO from '../dto/createAccountDTO';
|
||||
import { INewUserDTO } from '../dto/protocols';
|
||||
import createAcountRO from '../response-object/createAcountRO';
|
||||
import { CreateAccountROReturnType } from '../response-object/protocols';
|
||||
import ICreateAcountRepo from './ICreateAcountRepo';
|
||||
import { HttpHandler } from './protocols';
|
||||
|
||||
export default class CreateAccountRepo implements ICreateAcountRepo {
|
||||
private httpHandler: HttpHandler;
|
||||
|
||||
constructor(httpHandler: HttpHandler) {
|
||||
this.httpHandler = httpHandler;
|
||||
}
|
||||
|
||||
execute: (newUser: INewUserDTO) => Promise<CreateAccountROReturnType> =
|
||||
async (newUser: INewUserDTO) => {
|
||||
// call dto
|
||||
const dto = createAccountDTO(newUser);
|
||||
// call
|
||||
const newAccountResponse = await this.httpHandler(dto);
|
||||
// call response object
|
||||
const newAccount = createAcountRO(newAccountResponse);
|
||||
return newAccount;
|
||||
};
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
import { CreateAccountDTOReturnType } from '../dto/protocols';
|
||||
import { CreateAcountResponseApi } from '../response-object/protocols';
|
||||
|
||||
export type HttpHandler = (
|
||||
newUser: CreateAccountDTOReturnType
|
||||
) => Promise<CreateAcountResponseApi>;
|
@ -0,0 +1,13 @@
|
||||
import {
|
||||
CreateAccountROReturnType,
|
||||
CreateAcountResponseApi,
|
||||
} from './protocols';
|
||||
|
||||
const createAcountRO = (
|
||||
apiResponse: CreateAcountResponseApi
|
||||
): CreateAccountROReturnType => ({
|
||||
accountId: apiResponse.id,
|
||||
phonenumber: apiResponse.username,
|
||||
});
|
||||
|
||||
export default createAcountRO;
|
@ -0,0 +1,10 @@
|
||||
export type CreateAcountResponseApi = {
|
||||
nextRequestTimestamp: number;
|
||||
username: string;
|
||||
id: string;
|
||||
};
|
||||
|
||||
export type CreateAccountROReturnType = {
|
||||
phonenumber: string;
|
||||
accountId: string;
|
||||
};
|
@ -0,0 +1,5 @@
|
||||
import UsersModel from '../../../common/data/model/usersModel';
|
||||
|
||||
type ICreateUserRepo = () => Promise<UsersModel>;
|
||||
|
||||
export default ICreateUserRepo;
|
@ -0,0 +1,7 @@
|
||||
import ICreateUserRepo from './ICreateUserRepo';
|
||||
|
||||
const creatUserRepo = () => {
|
||||
|
||||
};
|
||||
|
||||
export default creatUserRepo;
|
@ -0,0 +1,14 @@
|
||||
import ICreateUserRepo from '../data/repository/ICreateUserRepo';
|
||||
|
||||
export default class CreateUserUsecase {
|
||||
private accountRepository: ICreateUserRepo;
|
||||
|
||||
constructor(repository: ICreateUserRepo) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
async execute() {
|
||||
// create acount
|
||||
// create profile by account ID
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user