Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResultT #5

Closed
gocandra opened this issue Sep 23, 2021 · 5 comments
Closed

ResultT #5

gocandra opened this issue Sep 23, 2021 · 5 comments

Comments

@gocandra
Copy link

gocandra commented Sep 23, 2021

I have the following problem using ResultT
`import { BaseUseCase, IResultT, ResultT } from "./base/BaseUseCase"
import { IPatientRepository, IPatient } from "@umahealth/repositories-module"

export class FindPatientUseCase extends BaseUseCase {
constructor(private readonly PatientRepository: IPatientRepository) {
super()
}
async execute(uid: string, patient: IPatient): Promise<IResultT> {
const result = new ResultT()
const patientExists: IPatient = await this.PatientRepository.getByUid(uid)
result.setData(patientExists, 200)
return result
}
}`

it says
Type 'Result<unknown>' is not assignable to type 'IResult<IPatient>'. Types of property 'data' are incompatible. Type 'unknown' is not assignable to type 'string | IPatient'. Type 'unknown' is not assignable to type 'IPatient'

I'm failling to understand how to properly use this library. Could you please give me some guidance?

@gocandra
Copy link
Author

I've just solved it... ajjajajjaajaja sry to bother
just for anyone else looking for this, you declare result like so.
const result = new ResultT()

@harvic3
Copy link
Owner

harvic3 commented Sep 23, 2021

Hi @gocandra result can be use with type ResultT (IResultT) o without type Result (IResult)
With type

const result = new ResultT<YourType>();

Without type

const result = new Result();

I hope this gives you more clarity about the use of this package.

@harvic3
Copy link
Owner

harvic3 commented Sep 23, 2021

I have the following problem using ResultT
`import { BaseUseCase, IResultT, ResultT } from "./base/BaseUseCase"
import { IPatientRepository, IPatient } from "@umahealth/repositories-module"

export class FindPatientUseCase extends BaseUseCase {
constructor(private readonly PatientRepository: IPatientRepository) {
super()
}
async execute(uid: string, patient: IPatient): Promise {
const result = new ResultT()
const patientExists: IPatient = await this.PatientRepository.getByUid(uid)
result.setData(patientExists, 200)
return result
}
}`

it says
Type 'Result<unknown>' is not assignable to type 'IResult<IPatient>'. Types of property 'data' are incompatible. Type 'unknown' is not assignable to type 'string | IPatient'. Type 'unknown' is not assignable to type 'IPatient'

I'm failling to understand how to properly use this library. Could you please give me some guidance?

@gocandra in this line, you can use the statusCode using Clean Code:

result.setData(patientExists, this.applicationStatus.SUCCESS,)

If you need create more aplication status codes, so you can map this status codes into the file StatusMapping in path:
src/adapters/controllers/base/httpResponse/

@gocandra
Copy link
Author

thanks! yeah, everything just fell into place afterwards. I was struggling at first with incorporating the whole framework into my head, but I fell that I'm now able to extract the most value out of this template. This is a very nice project, congrats!!

@harvic3
Copy link
Owner

harvic3 commented Sep 28, 2021

Thanks @gocandra, but don't forget to leave your star. It's a way to move the project forward and a form of support. ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants