Skip to content
Snippets Groups Projects
Commit 10fedeaf authored by Homar Franquesa Agil's avatar Homar Franquesa Agil
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
import { Module } from '@nestjs/common';
import { ItemsService } from './items.service';
import { ItemsController } from './items.controller';
@Module({
providers: [ItemsService],
controllers: [ItemsController],
})
export class ItemsModule {}
import { Injectable } from '@nestjs/common';
import { Item } from '../item';
import { Items } from '../items';
@Injectable()
export class ItemsService {
private readonly items: Items = {
1: {
id: 1,
name: 'Burger',
price: 5.99,
description: 'Tasty',
image: 'https://cdn.auth0.com/blog/whatabyte/burger-sm.png',
},
2: {
id: 2,
name: 'Pizza',
price: 2.99,
description: 'Cheesy',
image: 'https://cdn.auth0.com/blog/whatabyte/pizza-sm.png',
},
3: {
id: 3,
name: 'Tea',
price: 1.99,
description: 'Informative',
image: 'https://cdn.auth0.com/blog/whatabyte/tea-sm.png',
},
};
findAll(): Items {
return this.items;
}
create(newItem: Item): void {
const id = new Date().valueOf();
this.items[id] = {
...newItem,
id,
};
}
find(id: number): Item {
const record: Item = this.items[id];
if(record) {
return record;
}
throw new Error('No record found');
}
update(updatedItem: Item): void {
if (this.items[updatedItem.id]) {
this.items[updatedItem.id] = updatedItem
return;
}
throw new Error('No record found to update')
}
delete(id: number):void {
const record: Item = this.items[id];
if (record) {
delete this.items[id];
return;
}
throw new Error('No record found to delete');
}
}
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import * as dotenv from 'dotenv';
import { ValidationPipe } from '@nestjs/common';
dotenv.config();
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useGlobalPipes(new ValidationPipe());
await app.listen(process.env.PORT);
}
bootstrap();
import { Module } from '@nestjs/common';
import { UsersService } from './users.service';
@Module({
providers: [UsersService],
exports: [UsersService],
})
export class UsersModule {}
\ No newline at end of file
import { Injectable } from '@nestjs/common';
// This should be a real class/interface representing a user entity
export type User = any;
@Injectable()
export class UsersService {
private readonly users = [
{
userId: 1,
username: 'john',
password: 'changeme',
},
{
userId: 2,
username: 'maria',
password: 'guess',
},
];
async findOne(username: string): Promise<User | undefined> {
return this.users.find(user => user.username === username);
}
}
\ No newline at end of file
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
}
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment