Skip to content

Commit

Permalink
Merge pull request #5 from TeetouchQQ/main
Browse files Browse the repository at this point in the history
feat: offer
  • Loading branch information
TeetouchQQ authored Aug 3, 2023
2 parents 1e19694 + 88e77e8 commit 6d8bc4b
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { AuthModule } from './auth/auth.module';
import { TicketsModule } from './tickets/tickets.module';
import { TransactionModule } from './transaction/transaction.module';
import { UsersModule } from './users/users.module';
import { OfferModule } from './offer/offer.module';

@Module({
imports: [
Expand All @@ -30,6 +31,7 @@ import { UsersModule } from './users/users.module';
TicketsModule,
TransactionModule,
UsersModule,
OfferModule,
],
controllers: [AppController],
providers: [AppService],
Expand Down
13 changes: 13 additions & 0 deletions src/offer/dto/create-offer.dto.ts
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;
}
4 changes: 4 additions & 0 deletions src/offer/dto/update-offer.dto.ts
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) {}
1 change: 1 addition & 0 deletions src/offer/entities/offer.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class Offer {}
20 changes: 20 additions & 0 deletions src/offer/offer.controller.spec.ts
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();
});
});
34 changes: 34 additions & 0 deletions src/offer/offer.controller.ts
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);
}
}
14 changes: 14 additions & 0 deletions src/offer/offer.module.ts
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 {}
18 changes: 18 additions & 0 deletions src/offer/offer.service.spec.ts
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();
});
});
35 changes: 35 additions & 0 deletions src/offer/offer.service.ts
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`;
}
}
52 changes: 52 additions & 0 deletions src/offer/schemas/offer.schema.ts
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);

0 comments on commit 6d8bc4b

Please sign in to comment.