Unable to generate a mapping profile for DTO to entity conversion

Currently, I am utilizing NestJs in conjunction with the automapper library from https://github.com/nartc/mapper. Although I have a strong affinity for this library, it lacks structured documentation specifically tailored for NestJs. As a result, numerous errors remain undocumented. Interestingly, the library functions flawlessly within my other entities even when I am following identical procedures.
When attempting to execute the map creation process using the following line of code:

createMap(mapper, CreateUserDto, User);

I encounter the below-mentioned error message:
TypeError: Cannot convert undefined or null to object

Please extend your support by troubleshooting this issue.
Provided below are both my DTO and entity definitions:

import { IsArray, IsEmail, IsEnum, IsNotEmpty, IsNumber, IsOptional, IsString, ValidateNested } from "class-validator";
import { Type } from "class-transformer";
import { Scope } from "src/scope/scope.enum";
import { Status } from "src/status/status.enum";
import { ReadDepartmentDto } from "src/department/dept.dto";
import { ReadProjectDto } from "src/project/project.dto";
import { AutoMap } from "@automapper/classes";

// Include relevant attributes and methods

Entity Definition:

import { Scope } from "src/scope/scope.enum";
import { Exclude, instanceToPlain } from "class-transformer";
import { Department } from "src/department/dept.entity";
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, OneToMany } from "typeorm";
import { Project } from "src/project/project.entity";
import { Status } from "src/status/status.enum";
import { AutoMap } from "@automapper/classes";

// Include relevant attributes and methods  

Answer №1

Reference:

and

If you want to enhance your enum fields in both DTO and entity files, follow this pattern:

@AutoMap(() => [String])

Your code should look like this:

DTO

@IsEnum(Status, { each: true })
@AutoMap(() => [String])
statuses!: Status[];

Entity

@AutoMap(() => [String])
@Column({
    type: 'string',
    enum: Status,
    default: [Status.Active],
    array: true,
  })
  statuses!: Status[]

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Launching both client and server applications on the Heroku platform

I have a codebase structured as follows: rootfolder -- backend -- frontend -- .git The .git folder, and therefore the entire version control system, is located in the rootfolder. Each subfolder (backend and frontend) contains a package.json an ...

Detecting changes in Angular from the parent to the child component can be accomplished by utilizing a specific approach

The Sample Component contains data in the form of an array of objects with child components within a loop. Sample.component export class SampleComponent implements OnInit { data = [{ value: 3 }, { value: 1 }]; constructor() {} ngOnInit(): void {} ...

The unavailability of passed-in values during the runtime of a function within an Angular application

It's becoming clear to me that there is a piece of the puzzle missing when it comes to understanding exactly when certain function outputs are available in JavaScript. In my Angular application, I am trying to extract a user's initials by extrac ...

The export of ContainerSASPermissions from Azure Storage Blob is currently unavailable

I encountered an unusual import error: ./src/components/pages/DocumentationPage.tsx Attempted import error: 'ContainerSASPermissions' is not exported from '@azure/storage-blob'. The implementation in the azure documentation on GitHub c ...

Final Page Index (Backend pagination with Ng2-Smart-Table)

Currently, I am utilizing the Ng2-Smart-Table component along with server-side pagination. Upon testing out the provided example, I delved into the requests being made and noticed that only JSON records or objects were being returned. Here is an example of ...

Connecting to Multiple Databases in NestJS with MySQL Without Defining Entities

If you're interested in learning about connecting to MySQL using TypeORM and defining Entities, the NestJS documentation has all the information you need. In a situation where you have to connect to a MySQL server with multiple databases and need to ...

Transforming a plain text field into an input field upon clicking a button or icon using Angular/Typescript

I am a beginner with Angular 6 and I'm trying to implement functionality where clicking a button or icon will change a text field into an input field. See the snippet of code and expected output below. Thank you in advance. <div> <mat-for ...

The AngularJS Cross-Origin Resource Sharing (CORS) Policy

Our team is currently working on a web application using AngularJS that requires calling REST API services from another application. However, due to it being a cross domain request, we are facing difficulties in making the calls and receiving the following ...

Using Angular to access HTML content through the .ts file

Is there a way to retrieve the value of the input field [newUser] when clicking on the button and executing the action [onAddUser()] in the .ts file? <input type="text" ng-model="newUser" style="text-align:center"/> <button (cl ...

Having trouble with Angular's ActivatedRoute and paramMap.get('id')?

Currently, I am attempting to retrieve information from my server using the object's ID. The ID can be found in the URL as well: http://xyz/detail/5ee8cb8398e9a44d0df65455 In order to achieve this, I have implemented the following code in xyz.compo ...

Utilize React to iterate through data retrieved from firebase

I'm currently facing an issue with Google Firebase Realtime database where I am unable to create an array of the collection. Whenever I loop through the const return in console log, I receive messages as individual objects. However, what I actually n ...

How can I retrieve the `checked` state of an input in Vue 3 using Typescript?

In my current project, I am using the latest version of Vue (Vue 3) and TypeScript 4.4. I am facing an issue where I need to retrieve the value of a checkbox without resorting to (event.target as any).checked. Are there any alternative methods in Vue tha ...

Typescript interface created specifically for React Higher Order Component Props

Consider the React HOC provided below which adds sorting state to a component: import React, {Component, ComponentClass, ComponentType} from 'react' interface WithSortState { sortOrder: string } interface WithSortInjectedProps { sortO ...

Error occurs when attempting to access property on type 'unknown' without apparent cause

My current project involves an Angular application where I need to fetch data from a Rest API. There's a service that successfully retrieves the data and a component designed to display this data. However, during compilation of my application, I encou ...

Discover the data type of the subfield within an interface or type in Typescript

Check out the interface and type declarations provided below: interface Foo { bar: { a: number b: string } } type Foo = { bar: { a: number b: string } } Is it possible to obtain the type definitions for "baz"? This will allow us ...

Use the rowTemplate in a Kendo grid without replacing the existing one

I am currently utilizing Angular 1.4 with TypeScript and Kendo UI (employing angular directives). My goal is to create a RowTemplate for each row that dynamically changes the color based on a specific property of the item. While I am aware of jQuery solu ...

Customize buttons in Material UI using the styled component API provided by MUI

I am intrigued by the Material UI Styled Component API, not to be confused with the styled-component library. However, I am facing difficulty in converting my simple button component into a linked button. Can anyone advise me on how to incorporate a react ...

Troubleshooting Socket-io Client Problem After Migrating to TypeScript

I am currently in the process of migrating my MERN stack + Socket.io template to Typescript. However, I am encountering some issues specifically when transitioning the client code to Typescript. The Problem: My socket pings from socket.io-client are faili ...

Using mergeMap in conjunction with retryWhen allows for the resumption of retries from the exact point of failure, without needing

I have a list of URLs, the number of which is unknown until it stops (depending on some condition). This is how I am currently using them: from(observableUrls) .pipe( mergeMap(url => callHttpService(url) , 4), retryWhen( // Looking f ...

What is the reason behind Flow's reluctance to infer the function type from its return value?

I was anticipating the code to undergo type checking within Flow just like it does within TypeScript: var onClick : (() => void) | (() => boolean); onClick = () => { return true; } However, I encountered this error instead: 4: onClick = () => ...