Skip to content

Commit 337f028

Browse files
committed
chore: Remove unused code and update module imports
The commit removes the unused `app.controller.ts` and `app.service.ts` files. It also updates the `app.module.ts` file to import the `ListingModule` and remove the `AppController` and `AppService` imports. This cleanup improves the codebase by removing unnecessary files and updating the module imports.
1 parent bc8c811 commit 337f028

13 files changed

+154
-52
lines changed

src/app.controller.spec.ts

-22
This file was deleted.

src/app.controller.ts

-12
This file was deleted.

src/app.module.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { Module } from '@nestjs/common';
2-
import { AppController } from './app.controller';
3-
import { AppService } from './app.service';
42
import { CoreModule } from './core/core.module';
3+
import { ListingModule } from './modules/listing/listing.module';
54

65
@Module({
7-
imports: [CoreModule],
8-
controllers: [AppController],
9-
providers: [AppService],
6+
imports: [CoreModule, ListingModule],
7+
providers: [],
8+
controllers: [],
109
})
1110
export class AppModule {}

src/app.service.ts

-8
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the `User` table. If the table is not empty, all the data it contains will be lost.
5+
6+
*/
7+
-- DropTable
8+
DROP TABLE "User";
9+
10+
-- CreateTable
11+
CREATE TABLE "Listing" (
12+
"id" SERIAL NOT NULL,
13+
"label" TEXT NOT NULL,
14+
"addressLine1" TEXT NOT NULL,
15+
"addressLine2" TEXT,
16+
"addressCity" TEXT NOT NULL,
17+
"addressZipcode" TEXT NOT NULL,
18+
"addressState" TEXT NOT NULL,
19+
"price" INTEGER NOT NULL,
20+
"bathrooms" INTEGER NOT NULL,
21+
"bedrooms" INTEGER NOT NULL,
22+
"squareMeters" INTEGER NOT NULL,
23+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
24+
"updatedAt" TIMESTAMP(3) NOT NULL,
25+
26+
CONSTRAINT "Listing_pkey" PRIMARY KEY ("id")
27+
);

src/database/schema.prisma

+14-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,18 @@ datasource db {
77
url = env("DATABASE_URL")
88
}
99

10-
model User {
11-
id Int @id @default(autoincrement())
12-
email String @unique
13-
createdAt DateTime @default(now())
14-
updatedAt DateTime @updatedAt
10+
model Listing {
11+
id Int @id @default(autoincrement())
12+
label String
13+
addressLine1 String
14+
addressLine2 String?
15+
addressCity String
16+
addressZipcode String
17+
addressState String
18+
price Int
19+
bathrooms Int
20+
bedrooms Int
21+
squareMeters Int
22+
createdAt DateTime @default(now())
23+
updatedAt DateTime @updatedAt
1524
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { IsInt, IsNotEmpty, IsOptional, IsString, Min } from 'class-validator';
2+
import { CreateListingInput } from '../listing.types';
3+
4+
export class CreateListingDto implements CreateListingInput {
5+
@IsString()
6+
@IsNotEmpty()
7+
label: string;
8+
9+
@IsString()
10+
@IsNotEmpty()
11+
addressLine1: string;
12+
13+
@IsString()
14+
@IsNotEmpty()
15+
@IsOptional()
16+
addressLine2: string;
17+
18+
@IsString()
19+
@IsNotEmpty()
20+
addressCity: string;
21+
22+
@IsString()
23+
@IsNotEmpty()
24+
addressZipcode: string;
25+
26+
@IsString()
27+
@IsNotEmpty()
28+
addressState: string;
29+
30+
@IsInt()
31+
@Min(0)
32+
price: number;
33+
34+
@IsInt()
35+
@Min(0)
36+
bathrooms: number;
37+
38+
@IsInt()
39+
@Min(0)
40+
bedrooms: number;
41+
42+
@IsInt()
43+
@Min(0)
44+
squareMeters: number;
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { PartialType } from '@nestjs/mapped-types';
2+
import { CreateListingDto } from './create-listing.dto';
3+
4+
export class UpdateListingDto extends PartialType(CreateListingDto) {}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Controller, Post, Body } from '@nestjs/common';
2+
import { ListingService } from './listing.service';
3+
import { CreateListingDto } from './dto/create-listing.dto';
4+
5+
@Controller('listing')
6+
export class ListingController {
7+
constructor(private readonly listingService: ListingService) {}
8+
9+
@Post()
10+
create(@Body() createListingDto: CreateListingDto) {
11+
return this.listingService.create(createListingDto);
12+
}
13+
}

src/modules/listing/listing.module.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Module } from '@nestjs/common';
2+
import { ListingService } from './listing.service';
3+
import { ListingController } from './listing.controller';
4+
5+
@Module({
6+
controllers: [ListingController],
7+
providers: [ListingService],
8+
})
9+
export class ListingModule {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Test, TestingModule } from '@nestjs/testing';
2+
import { ListingService } from './listing.service';
3+
4+
describe('ListingService', () => {
5+
let service: ListingService;
6+
7+
beforeEach(async () => {
8+
const module: TestingModule = await Test.createTestingModule({
9+
providers: [ListingService],
10+
}).compile();
11+
12+
service = module.get<ListingService>(ListingService);
13+
});
14+
15+
it('should be defined', () => {
16+
expect(service).toBeDefined();
17+
});
18+
});
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Injectable } from '@nestjs/common';
2+
import { CreateListingDto } from './dto/create-listing.dto';
3+
import { DatabaseService } from '../../database/database.service';
4+
5+
@Injectable()
6+
export class ListingService {
7+
constructor(private readonly databaseService: DatabaseService) {}
8+
9+
async create(createListingDto: CreateListingDto) {
10+
return await this.databaseService.listing.create({
11+
data: createListingDto,
12+
});
13+
}
14+
}

src/modules/listing/listing.types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Listing as PrismaListing } from '@prisma/client';
2+
3+
export type CreateListingInput = Omit<
4+
PrismaListing,
5+
'id' | 'createdAt' | 'updatedAt'
6+
>;

0 commit comments

Comments
 (0)