-
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.
feat: create votes and cast logic without smco yet
- Loading branch information
1 parent
58ec7c1
commit aa3080f
Showing
15 changed files
with
185 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,3 +42,4 @@ Thumbs.db | |
.nx/workspace-data | ||
|
||
.angular | ||
.env |
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 |
---|---|---|
@@ -1,13 +1,9 @@ | ||
import { Controller, Get } from '@nestjs/common'; | ||
import {Controller, Get} from '@nestjs/common'; | ||
|
||
import { AppService } from './app.service'; | ||
import {AppService} from './app.service'; | ||
|
||
@Controller() | ||
export class AppController { | ||
constructor(private readonly appService: AppService) {} | ||
|
||
@Get() | ||
getData() { | ||
return this.appService.getData(); | ||
constructor(private readonly appService: AppService) { | ||
} | ||
} |
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 |
---|---|---|
@@ -1,11 +1,27 @@ | ||
import { Module } from '@nestjs/common'; | ||
import {Module} from '@nestjs/common'; | ||
|
||
import { AppController } from './app.controller'; | ||
import { AppService } from './app.service'; | ||
import {AppController} from './app.controller'; | ||
import {AppService} from './app.service'; | ||
import {ConfigModule, ConfigService} from "@nestjs/config"; | ||
import {MongooseModule} from "@nestjs/mongoose"; | ||
import {VotesModule} from "./votes/votes.module"; | ||
import {CastModule} from "./casts/cast.module"; | ||
|
||
@Module({ | ||
imports: [], | ||
imports: [ | ||
ConfigModule.forRoot(), | ||
MongooseModule.forRootAsync({ | ||
imports: [ConfigModule], | ||
useFactory: async (configService: ConfigService) => ({ | ||
uri: configService.get<string>('MONGODB_URI'), | ||
}), | ||
inject: [ConfigService], | ||
}), | ||
VotesModule, | ||
CastModule | ||
], | ||
controllers: [AppController], | ||
providers: [AppService], | ||
}) | ||
export class AppModule {} | ||
export class AppModule { | ||
} |
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,18 @@ | ||
import { Controller, Post, Body, Param, Get } from '@nestjs/common'; | ||
import {CastService} from "./cast.service"; | ||
import {CreateCastDto} from "./dto/create-cast.dto"; | ||
|
||
@Controller('casts') | ||
export class CastController { | ||
constructor(private readonly castService: CastService) {} | ||
|
||
@Post() | ||
async create(@Body() createCastDto: CreateCastDto) { | ||
return this.castService.create(createCastDto); | ||
} | ||
|
||
@Get(':voteId') | ||
async findByVoteId(@Param('voteId') voteId: string) { | ||
return this.castService.findByVoteId(voteId); | ||
} | ||
} |
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,12 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { MongooseModule } from '@nestjs/mongoose'; | ||
import {Cast, CastSchema} from "./schemas/casts.schema"; | ||
import {CastController} from "./cast.controller"; | ||
import {CastService} from "./cast.service"; | ||
|
||
@Module({ | ||
imports: [MongooseModule.forFeature([{ name: Cast.name, schema: CastSchema }])], | ||
controllers: [CastController], | ||
providers: [CastService], | ||
}) | ||
export class CastModule {} |
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,19 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { InjectModel } from '@nestjs/mongoose'; | ||
import { Model } from 'mongoose'; | ||
import {Cast} from "./schemas/casts.schema"; | ||
import {CreateCastDto} from "./dto/create-cast.dto"; | ||
|
||
@Injectable() | ||
export class CastService { | ||
constructor(@InjectModel(Cast.name) private CastModel: Model<Cast>) {} | ||
|
||
async create(createCastDto: CreateCastDto): Promise<Cast> { | ||
const createdCast = new this.CastModel(createCastDto); | ||
return createdCast.save(); | ||
} | ||
|
||
async findByVoteId(voteId: string): Promise<Cast[]> { | ||
return this.CastModel.find({ voteId }).exec(); | ||
} | ||
} |
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,5 @@ | ||
export class CreateCastDto { | ||
voteId: string; | ||
selectedOption: string; | ||
voterPublicKey: string; | ||
} |
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,19 @@ | ||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; | ||
import { Document, Schema as MongooseSchema } from 'mongoose'; | ||
|
||
@Schema() | ||
export class Cast extends Document { | ||
@Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Vote', required: true }) | ||
voteId: string; | ||
|
||
@Prop({ required: true }) | ||
selectedOption: string; | ||
|
||
@Prop({ required: true }) | ||
voterPublicKey: string; // Public key of the voter's wallet | ||
|
||
@Prop({ default: Date.now }) | ||
createdAt: Date; | ||
} | ||
|
||
export const CastSchema = SchemaFactory.createForClass(Cast); |
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,6 @@ | ||
export class CreateVoteDto { | ||
title: string; | ||
description: string; | ||
options: string[]; | ||
createdBy: string; | ||
} |
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,22 @@ | ||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; | ||
import { Document } from 'mongoose'; | ||
|
||
@Schema() | ||
export class Vote extends Document { | ||
@Prop({ required: true }) | ||
title: string; | ||
|
||
@Prop({ required: true }) | ||
description: string; | ||
|
||
@Prop({ required: true }) | ||
options: string[]; | ||
|
||
@Prop({ default: Date.now }) | ||
createdAt: Date; | ||
|
||
@Prop({ required: true }) | ||
createdBy: string; // Public key of the creator's wallet | ||
} | ||
|
||
export const VoteSchema = SchemaFactory.createForClass(Vote); |
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,23 @@ | ||
import { Controller, Get, Post, Body, Param } from '@nestjs/common'; | ||
import { VotesService } from './votes.service'; | ||
import { CreateVoteDto } from './dto/create-vote.dto'; | ||
|
||
@Controller('votes') | ||
export class VotesController { | ||
constructor(private readonly votesService: VotesService) {} | ||
|
||
@Post() | ||
async create(@Body() createVoteDto: CreateVoteDto) { | ||
return this.votesService.create(createVoteDto); | ||
} | ||
|
||
@Get() | ||
async findAll() { | ||
return this.votesService.findAll(); | ||
} | ||
|
||
@Get(':id') | ||
async findOne(@Param('id') id: string) { | ||
return this.votesService.findOne(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,12 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { MongooseModule } from '@nestjs/mongoose'; | ||
import { VotesController } from './votes.controller'; | ||
import { VotesService } from './votes.service'; | ||
import { Vote, VoteSchema } from './schemas/vote.schema'; | ||
|
||
@Module({ | ||
imports: [MongooseModule.forFeature([{ name: Vote.name, schema: VoteSchema }])], | ||
controllers: [VotesController], | ||
providers: [VotesService], | ||
}) | ||
export class VotesModule {} |
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,23 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { InjectModel } from '@nestjs/mongoose'; | ||
import { Model } from 'mongoose'; | ||
import { Vote } from './schemas/vote.schema'; | ||
import { CreateVoteDto } from './dto/create-vote.dto'; | ||
|
||
@Injectable() | ||
export class VotesService { | ||
constructor(@InjectModel(Vote.name) private voteModel: Model<Vote>) {} | ||
|
||
async create(createVoteDto: CreateVoteDto): Promise<Vote> { | ||
const createdVote = new this.voteModel(createVoteDto); | ||
return createdVote.save(); | ||
} | ||
|
||
async findAll(): Promise<Vote[]> { | ||
return this.voteModel.find().exec(); | ||
} | ||
|
||
async findOne(id: string): Promise<Vote> { | ||
return this.voteModel.findById(id).exec(); | ||
} | ||
} |
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