Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
fey committed Jun 6, 2024
1 parent 38a0f8f commit 2c8501b
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 28 deletions.
3 changes: 3 additions & 0 deletions backend/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ settings:
- .ts

rules:
class-methods-use-this:
- 2
- exceptMethods: ["up", "down"]
import/no-cycle: [2, { maxDepth: 1 }]
import/prefer-default-export: 0
import/extensions: 0
Expand Down
7 changes: 3 additions & 4 deletions backend/src/config/data-source.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { DataSourceOptions } from 'typeorm';

export default (): DataSourceOptions => {
const defaultConfig = {
entities: [ __dirname + `/../entities/**/*{.ts,.js}`],
migrations: [ __dirname + `/../migrations/**/*{.ts,.js}`],

entities: [`${__dirname}/../entities/**/*{.ts,.js}`],
migrations: [`${__dirname}/../migrations/**/*{.ts,.js}`],
};
switch (process.env.NODE_ENV) {
case 'production':
Expand All @@ -23,7 +23,6 @@ export default (): DataSourceOptions => {
type: 'sqlite',
database: ':memory:',
synchronize: true,

};
default:
return {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/entities/snippet.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm';
import { User } from './user.entity';
import type { User } from './user.entity';

@Entity('snippets')
export class Snippet {
Expand All @@ -26,7 +26,7 @@ export class Snippet {
@Column('text')
language: string;

@ManyToOne(() => User, (user) => user.snippets)
@ManyToOne('User', 'snippets')
@JoinColumn()
user: User;

Expand Down
4 changes: 2 additions & 2 deletions backend/src/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
UpdateDateColumn,
} from 'typeorm';
import { encrypt } from '../users/secure/encrypt';
import { Snippet } from './snippet.entity';
import type { Snippet } from './snippet.entity';

@Entity('users')
export class User {
Expand All @@ -28,7 +28,7 @@ export class User {
@Column('text')
password: string;

@OneToMany(() => Snippet, (snippet) => snippet.user)
@OneToMany('Snippet', 'user')
snippets: Snippet[];

@Column({ nullable: true })
Expand Down
13 changes: 6 additions & 7 deletions backend/src/migrations/1699462100238-migrations.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* eslint class-methods-use-this: ["error", { "exceptMethods": ["up", "down"] }] */
import { MigrationInterface, QueryRunner, Table } from 'typeorm';

export class Migrations1699462100238 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'users',
Expand Down Expand Up @@ -114,10 +113,10 @@ export class Migrations1699462100238 implements MigrationInterface {
],
}),
);
}
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE "snippets"`);
await queryRunner.query(`DROP TABLE "users"`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE "snippets"`);
await queryRunner.query(`DROP TABLE "users"`);
}
}
26 changes: 14 additions & 12 deletions backend/src/migrations/1717697901307-fix-old-snippets-language.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { Snippet } from "../entities/snippet.entity"
import { MigrationInterface, QueryRunner } from "typeorm"
import { MigrationInterface, QueryRunner } from 'typeorm';
import { Snippet } from '../entities/snippet.entity';

export class FixOldSnippetsLanguage1717697901307 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.manager.getRepository(Snippet).createQueryBuilder()
.update()
.set({ language: "javascript" })
.where("language IS NULL")
.execute();
}

public async down(queryRunner: QueryRunner): Promise<void> {
}
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.manager
.getRepository(Snippet)
.createQueryBuilder()
.update()
.set({ language: 'javascript' })
.where('language IS NULL')
.execute();
}

public async down(): Promise<void> {
// nothing
}
}
4 changes: 3 additions & 1 deletion backend/src/snippets/snippets.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ export class SnippetsController {

@Get(':id')
@ApiOkResponse({ description: 'Successfully returned snippet by id' })
async findOne(@Param('id', new ParseIntPipe()) id: number): Promise<ISnippet> {
async findOne(
@Param('id', new ParseIntPipe()) id: number,
): Promise<ISnippet> {
return this.snippetsService.findOne(id);
}

Expand Down

0 comments on commit 2c8501b

Please sign in to comment.