-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from TeetouchQQ/main
feat: offer
- Loading branch information
Showing
10 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { TimePeriod, Contract } from '../schemas/offer.schema'; | ||
export class CreateOfferDto { | ||
type: string; | ||
project_name: string; | ||
description: string; | ||
owner: string; | ||
time_period: TimePeriod; | ||
contact: Contract; | ||
price_by_unit: number; | ||
_id: string; | ||
image: string; | ||
maximum: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { PartialType } from '@nestjs/swagger'; | ||
import { CreateOfferDto } from './create-offer.dto'; | ||
|
||
export class UpdateOfferDto extends PartialType(CreateOfferDto) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export class Offer {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { OfferController } from './offer.controller'; | ||
import { OfferService } from './offer.service'; | ||
|
||
describe('OfferController', () => { | ||
let controller: OfferController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [OfferController], | ||
providers: [OfferService], | ||
}).compile(); | ||
|
||
controller = module.get<OfferController>(OfferController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; | ||
import { OfferService } from './offer.service'; | ||
import { CreateOfferDto } from './dto/create-offer.dto'; | ||
import { UpdateOfferDto } from './dto/update-offer.dto'; | ||
|
||
@Controller('offer') | ||
export class OfferController { | ||
constructor(private readonly offerService: OfferService) {} | ||
|
||
@Post() | ||
create(@Body() createOfferDto: CreateOfferDto) { | ||
return this.offerService.create(createOfferDto); | ||
} | ||
|
||
@Get() | ||
findAll() { | ||
return this.offerService.findAll(); | ||
} | ||
|
||
@Get(':id') | ||
findOne(@Param('id') id: string) { | ||
return this.offerService.findOne(+id); | ||
} | ||
|
||
@Patch(':id') | ||
update(@Param('id') id: string, @Body() updateOfferDto: UpdateOfferDto) { | ||
return this.offerService.update(+id, updateOfferDto); | ||
} | ||
|
||
@Delete(':id') | ||
remove(@Param('id') id: string) { | ||
return this.offerService.remove(+id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { OfferService } from './offer.service'; | ||
import { OfferController } from './offer.controller'; | ||
import {MongooseModule} from '@nestjs/mongoose'; | ||
|
||
import { Offer, OfferSchema } from './schemas/offer.schema'; | ||
@Module({ | ||
imports: [ | ||
MongooseModule.forFeature([{ name: Offer.name, schema: OfferSchema }]), | ||
], | ||
controllers: [OfferController], | ||
providers: [OfferService] | ||
}) | ||
export class OfferModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { OfferService } from './offer.service'; | ||
|
||
describe('OfferService', () => { | ||
let service: OfferService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [OfferService], | ||
}).compile(); | ||
|
||
service = module.get<OfferService>(OfferService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { CreateOfferDto } from './dto/create-offer.dto'; | ||
import { UpdateOfferDto } from './dto/update-offer.dto'; | ||
import { Offer ,OfferDocument} from './schemas/offer.schema'; | ||
|
||
import { InjectModel } from '@nestjs/mongoose'; | ||
import { Model } from 'mongoose'; | ||
|
||
|
||
@Injectable() | ||
export class OfferService { | ||
constructor( | ||
@InjectModel(Offer.name) private offerModel: Model<OfferDocument>, | ||
) {} | ||
|
||
async create(createOfferDto: CreateOfferDto) { | ||
return await this.offerModel.create(createOfferDto); | ||
} | ||
|
||
findAll() { | ||
return `This action returns all offer`; | ||
} | ||
|
||
findOne(id: number) { | ||
return `This action returns a #${id} offer`; | ||
} | ||
|
||
update(id: number, updateOfferDto: UpdateOfferDto) { | ||
return `This action updates a #${id} offer`; | ||
} | ||
|
||
remove(id: number) { | ||
return `This action removes a #${id} offer`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; | ||
import { HydratedDocument, Document } from 'mongoose'; | ||
|
||
|
||
export type OfferDocument = Offer & HydratedDocument<Offer>; | ||
|
||
export interface TimePeriod { | ||
start: Date; | ||
end: Date; | ||
} | ||
|
||
export interface Contract { | ||
name:string; | ||
email:string; | ||
tel:number; | ||
} | ||
|
||
@Schema() | ||
export class Offer extends Document { | ||
@Prop({ required: true }) | ||
type: string; | ||
|
||
@Prop({ required: true }) | ||
project_name:string; | ||
|
||
@Prop({ required: true }) | ||
description:string; | ||
|
||
@Prop({ required: true }) | ||
owner:string; | ||
|
||
@Prop({ required: true, | ||
type: Object | ||
}) | ||
time_period:TimePeriod; | ||
|
||
@Prop({ required: true }) | ||
price_by_unit:number; | ||
|
||
@Prop({ required: true , | ||
type: Object | ||
}) | ||
contract:Contract; | ||
|
||
@Prop({ required: true }) | ||
image:string; | ||
|
||
@Prop({ required: true }) | ||
maximun:5; | ||
} | ||
|
||
export const OfferSchema = SchemaFactory.createForClass(Offer); |