What is the best method for retrieving database table content in NestJS?

In MySQL, I successfully created a database named refy with a single table labeled app.

https://i.sstatic.net/BI8VD.png

My current focus is on utilizing NestJS to retrieve all columns from the mentioned table:

import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
import { App } from 'src/database/refy/app.entity';

@Controller()
export class AppController {
    constructor(private readonly refyService: AppService) {}

    @Get('/refy')
    findAll(): Promise<App[]> {
        return this.refyService.findAll();
    }
}

The entity file structure includes:

import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';

@Entity({name: 'app'})
export class App {
  
    @PrimaryGeneratedColumn()
    id: number;
  
    @Column()
    name: string;
    
    @Column()
    webhookSecretKey: string;
  
    @Column()
    webhookUrl: string;
  
    @Column()
    clientId: string;
  
    @Column()
    clientSecretKey: string;
}

Even though the database connection seems intact and operational, Postman returns a 500 error when retrieving data:

https://i.sstatic.net/H4b7y.png

An error message appears in the terminal debug:

EntityMetadataNotFoundError: No metadata for "App" was found

The desired data output format should resemble this:

{
    "webhookSecretKey": "1",
    "webhookUrl": "2",
    "clientId": "3",
    "clientSecretKey": "4",
    "id": 5,
    "name": "6"
}

Answer №1

There are two primary reasons why this issue may occur:

  1. The OrmConfig contains an incorrect path, which can be corrected by updating it as follows:
entities: [__dirname + '/../**/*.entity.{js,ts}']
  1. You may have unintentionally omitted adding the entity App to the TypeOrmModule.forRoot within the imports array of the main module:
imports: [
TypeOrmModule.forRoot({
  entities: [App]
}),
],

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

Why does TypeScript not recognize deconstructed arrays as potentially undefined variables?

When looking at the code snippet below, I was under the impression that the destructured array variables, firstName and lastName, would be classified as string | undefined. This is because the array being destructured could have fewer variables compared ...

What is the reasoning behind not allowing an empty object as the initial value for hooks?

I am encountering an issue with my setProd Hooks. export interface faceProduct { readonly title: string; readonly prodState: string; readonly shipping: string; readonly sold: string; readonly alt: string; readonly material: string; readonly ...

What is the best way to set up an empty constructor with a nested object?

Currently struggling with this issue in my code: I am unable to correctly initialize the nestedStudents property. Every attempt results in an error suggesting the object may be undefined. export class StudentDto { students: number; nestedStudents: { ...

What is the importance of typescript requiring the use of generics?

const typeFunction = <T>(a:string, {c,d} = {c: T[], D:T} = {})=>{} In what way does TypeScript enforce the usage of generics? I am looking to create a function that requires a specific type (T) to be passed in when it is used. typeFunction<st ...

Organizing a React Navigation App with a Visible Tab Bar

I have a clear image that demonstrates the problem https://i.sstatic.net/M2Hl7.png This is a simplified overview of the app structure. There is a tab bar navigator with three screens labeled A B C. TabBar A consists of a stack navigator containing D and ...

Creating a webpage with a form is a simple process that involves utilizing both PHP and HTML

Just like creating a post in WordPress or asking a question on this website, I am curious about how to create a page simply by filling out a form. I understand how to build an HTML form, manage data in a database, and have some knowledge of PHP. However, ...

What is the syntax for using typeof with anonymous types in TypeScript?

After reading an article, I'm still trying to grasp the concept of using typeof in TypeScript for real-world applications. I understand it's related to anonymous types, but could someone provide a practical example of how it can be used? Appreci ...

Tips for utilizing both the mysql and sqlserver database functions within a single PHP document

My application is built using PHP and MySQL, with the addition of SQL Server. However, I am facing an issue where the application shows a blank page when retrieving records from the SQL Server database based on a search criteria value (this value resides ...

The air-datepicker functionality seems to be malfunctioning within an Angular 4 environment

When using static HTML, it's quite simple to integrate Air Datepicker by following the documentation available at : <html> <head> <link href="dist/css/datepicker.min.css" rel="stylesheet" type="text/css"> <scr ...

Unlock the full potential of p-checkbox with PrimeNG's trueValue and falseValue feature

I've been attempting to incorporate a p-checkbox in Angular8 with true and false values as strings instead of booleans. So I tested the following code: <p-checkbox [(ngModel)]="mycheckbox" name="mycheckbox" inputId="mycheck ...

Seeking assistance with crafting an SQL query

There are two tables in my database: CREATE TABLE `workers` ( `id` int(7) NOT NULL AUTO_INCREMENT, `number` int(7) NOT NULL, `percent` int(3) NOT NULL, `order` int(7) NOT NULL, PRIMARY KEY (`id`) ); CREATE `data` ( `id` bigint(15) NOT N ...

Unusual Conduct when Interacting with ContentEditable Text

Looking for help with a strange issue that I can't seem to figure out. Hopefully someone has encountered this before and might have a solution. In my Angular app, I'm using a contenteditable <div> for inputting content, which is working fi ...

The DBGrid and DataSet are not sorting the data as specified in the SQL statement provided in the CommandText

In my application, I have set the CommandText property of the DataSet to the following query: SELECT * FROM table_name ORDER BY FIELD(priority, 'urgent', 'normal'), FIELD(state, 'wait', 'executed', 'do ...

Checking a sequence using a list of strings

I have an array containing a list of IDs: var listId: string[] = []; var newId: boolean; for (let i in data.chunk) { listId.push(data.chunk[i].aliases[0]); } My objective is to compare a new ID with the entire list. If the new ID is found in the list ...

What steps should I take to resolve an unhandled promise error in a React TypeScript application while making an axios POST request?

I am currently working on a .tsx file to implement adding an enterprise feature. Although I can input data, clicking the submit button does not trigger any action. My application includes a page that has a button for adding a new enterprise. Upon clickin ...

Leveraging AnimatePresence from the Framer Motion library to design an exit animation for a motion.div

My goal is to implement a side menu that smoothly slides in and out when the menu/close button is clicked using framer motion. Initially, clicking on the menu button will cause the menu to slide out from the left side of the screen while changing the butto ...

Error encountered when trying to call a member function on a non-object within a MySQL prepared statement

I'm in the process of implementing a Follow profile feature on my website. My current setup includes a Follow button that toggles to Unfollow if there is a corresponding row in the database linking the profile ID and session ID. However, when attempt ...

The art of representing objects and generating JSON responses

As I dive into building a web application using NextJS, a versatile framework for both API and user interface implementation, I find myself pondering the best practices for modeling and handling JSON responses. Key Points In my database, models are store ...

Finding it challenging to adapt an AngularJs component-based modal to TypeScript

When creating an AngularJS component in JavaScript and displaying it as a modal using ui-bootstrap, you need to pass bindings that the modal instance can use for dismissing or closing itself: app.component("fringeEdit", { controller: "FringeEditCont ...

Issue with ngFor displaying only the second item in the array

There are supposed to be two editable input fields for each section, with corresponding data. However, only the second JSON from the sample is being displayed in both sections. The JSON in the TypeScript file appears as follows: this.sample = [ { "se ...