-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
600 additions
and
248 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,22 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
function usage() { | ||
echo -n \ | ||
"Usage: $(basename "$0") [migration_name] | ||
Run migrations using typeorm. | ||
" | ||
} | ||
|
||
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then | ||
if [ "${1:-}" = "--help" ]; then | ||
usage | ||
else | ||
docker-compose up -d \ | ||
database app-backend-yarn | ||
|
||
docker-compose \ | ||
run --rm app-backend-yarn "migration:run" | ||
fi | ||
fi |
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 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
function usage() { | ||
echo -n \ | ||
"Usage: $(basename "$0") [migration_name] | ||
Generates a migration using typeorm. | ||
" | ||
} | ||
|
||
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then | ||
if [ "${1:-}" = "--help" ]; then | ||
usage | ||
else | ||
docker-compose up -d \ | ||
database app-backend-yarn | ||
|
||
docker-compose \ | ||
run --rm app-backend-yarn "migration:generate" "$@" | ||
fi | ||
fi |
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 {MigrationInterface, QueryRunner} from "typeorm"; | ||
|
||
export class CreateUserTable1580263521268 implements MigrationInterface { | ||
readonly name = 'CreateUserTable1580263521268' | ||
|
||
public async up(queryRunner: QueryRunner): Promise<any> { | ||
await queryRunner.query(`CREATE TABLE "user" ("id" SERIAL NOT NULL, "email" character varying NOT NULL, CONSTRAINT "UQ_e12875dfb3b1d92d7d7c5377e22" UNIQUE ("email"), CONSTRAINT "PK_cace4a159ff9f2512dd42373760" PRIMARY KEY ("id"))`, undefined); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<any> { | ||
await queryRunner.query(`DROP TABLE "user"`, undefined); | ||
} | ||
|
||
} |
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 @@ | ||
const process = require('process'); | ||
const username = process.env.POSTGRES_USER; | ||
const password = process.env.POSTGRES_PASSWORD; | ||
module.exports = { | ||
"type": "postgres", | ||
"host": "database.service.districtbuilder.internal", | ||
"port": 5432, | ||
username, | ||
password, | ||
"database": "postgres", | ||
"synchronize": true, | ||
"dropSchema": false, | ||
"logging": true, | ||
"entities": [__dirname + "/src/**/*.entity.ts", __dirname + "/dist/**/*.entity.js"], | ||
"migrations": ["migrations/**/*.ts"], | ||
"subscribers": ["subscriber/**/*.ts", "dist/subscriber/**/.js"], | ||
"cli": { | ||
"entitiesDir": "src", | ||
"migrationsDir": "migrations", | ||
"subscribersDir": "subscriber" | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
src/server/src/users/controllers/users/users.controller.spec.ts
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 { UsersController } from "./users.controller"; | ||
|
||
describe("Users Controller", () => { | ||
let controller: UsersController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [UsersController] | ||
}).compile(); | ||
|
||
controller = module.get<UsersController>(UsersController); | ||
}); | ||
|
||
it("should be defined", () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
src/server/src/users/controllers/users/users.controller.ts
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 { Controller } from "@nestjs/common"; | ||
import { Crud, CrudController } from "@nestjsx/crud"; | ||
import { User } from "../../entities/user.entity"; | ||
import { UsersService } from "../../services/users/users.service"; | ||
|
||
@Crud({ | ||
model: { | ||
type: User | ||
} | ||
}) | ||
@Controller("users") | ||
export class UsersController implements CrudController<User> { | ||
constructor(public service: UsersService) {} | ||
} |
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,8 @@ | ||
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm"; | ||
@Entity() | ||
export class User { | ||
@PrimaryGeneratedColumn() | ||
readonly id: string; | ||
@Column({ unique: true }) | ||
readonly email: 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,18 @@ | ||
import { Test, TestingModule } from "@nestjs/testing"; | ||
import { UsersService } from "./users.service"; | ||
|
||
describe("UsersService", () => { | ||
let service: UsersService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [UsersService] | ||
}).compile(); | ||
|
||
service = module.get<UsersService>(UsersService); | ||
}); | ||
|
||
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,12 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import { InjectRepository } from "@nestjs/typeorm"; | ||
import { TypeOrmCrudService } from "@nestjsx/crud-typeorm"; | ||
import { Repository } from "typeorm"; | ||
import { User } from "../../entities/user.entity"; | ||
|
||
@Injectable() | ||
export class UsersService extends TypeOrmCrudService<User> { | ||
constructor(@InjectRepository(User) usersRepository: Repository<User>) { | ||
super(usersRepository); | ||
} | ||
} |
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,11 @@ | ||
import { Module } from "@nestjs/common"; | ||
import { TypeOrmModule } from "@nestjs/typeorm"; | ||
import { UsersController } from "./controllers/users/users.controller"; | ||
import { User } from "./entities/user.entity"; | ||
import { UsersService } from "./services/users/users.service"; | ||
@Module({ | ||
imports: [TypeOrmModule.forFeature([User])], | ||
controllers: [UsersController], | ||
providers: [UsersService] | ||
}) | ||
export class UsersModule {} |
Oops, something went wrong.