You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to map a DTO (RequestDto) which has an array of numbers (selectedFacilities) to an array of custom objects (CenterFacilities) that has two ids: a centerId. that is the id of the center (this is something that I receive from the token and) and the facilityId that is an id in the selectedFacilities list
So this is the DTO I receive from the client:
export class RequestDto {
description!: string
selectedFacilities?: number[]
}
I need to convert a RequestDto to Center
This is how a Center looks like:
export interface CenterAttributes {
description: string
facilities: CenterFacility[]
}
export class Center extends BaseModel<CenterAttributes> {
description!: string
facilities!: Array<Facility & { CenterFacility: CenterFacility }>
}
interface CenterFacilityAttributes {
centerId: number
facilityId: number
}
export class CenterFacility extends BaseModel<CenterFacilityAttributes> {
centerId!: number
facilityId!: number
}
So I tried several ways with mapWith and mapArray but wasn't able to find too much information about that.
Is there any possibility to map a list of numbers to a list of CenterFacility?
each selectedFacilities is a facilityId in the CenterFacility. The other id, the centerId, will be a fixed number that I should pass as a prop (maybe with mapWithArguments)?
This discussion was converted from issue #361 on October 26, 2021 19:41.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Is there an existing issue for this?
Describe the issue
I want to map a DTO
(RequestDto)
which has an array of numbers(selectedFacilities)
to an array of custom objects (CenterFacilities
) that has two ids: acenterId
. that is the id of the center (this is something that I receive from the token and) and thefacilityId
that is an id in theselectedFacilities
listSo this is the DTO I receive from the client:
I need to convert a RequestDto to Center
This is how a Center looks like:
So I tried several ways with
mapWith
andmapArray
but wasn't able to find too much information about that.Is there any possibility to map a list of numbers to a list of CenterFacility?
each
selectedFacilities
is afacilityId
in theCenterFacility
. The other id, thecenterId
, will be a fixed number that I should pass as a prop (maybe with mapWithArguments)?This is what I tried:
all those comment lines were possibilities I tried without luck.
Mapping configuration
Note
I need to do a manual mapping.
Package
@automapper/core
@automapper/classes
@automapper/nestjs
@automapper/pojos
@automapper/sequelize
@automapper/types
AutoMapper version
6.2.1
Beta Was this translation helpful? Give feedback.
All reactions