DEV Community

Kipack Jeong
Kipack Jeong

Posted on

Dev note 7JAN2021


git diff

git diff command is to view the changes.

git diff - list all the changes in our working directory that are not staged.
git diff HEAD - list all the changes between working directory and HEAD.
git diff branch1 branch2 - list all the changes between branch1 and branch2
git diff --staged - list all the changes between working directory and staged.

git stash

  • when you want to temporarily save changes without committing them before switching over to different branch.
  • is not mandatory command.
  • it just makes more convenient.

git stash: stash the current work.
git stash pop : pop recent stash.
git stash apply: User to apply whatever stashed away, without removing it from the stash. This can be useful if you want to apply stashed changes to multiple branches.
git stash list : shows all the stashes.
git stash apply : apply particular stash to current branch.
git stash drop : delete particular stash.


Hashing Password

Hashed password cannot be decrypted.

To secure user from rainbow table, need to use salt.

So the step to save password is.

  • when user inputs plain text version of password.
  • salt it.
  • then hash it.
  • then save it in db.

Library to encrypt password.

  • bcrypt not only hash password, but also salt it.
import * as bcrypt from 'bcrypt'

const salt = bcrypt.genSalt()
const hashedPassword = bcrypt.hash(password, salt)
const createdUser = user.create({username,password:hashedPassword})
Enter fullscreen mode Exit fullscreen mode

Many to One and One to Many


import { Exclude } from 'class-transformer';
import { User } from 'src/users/user.entity';
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';

export class Task {
    id: string;

    title: string;

    @ManyToOne((_type) => User, (user) => user.tasks, { eager: false })
    @Exclude({ toPlainOnly: true })
    user: User;
Enter fullscreen mode Exit fullscreen mode


export class User {
    id: string;

    @Column({ unique: true })
    username: string;

    password: string;

    @OneToMany((_type) => Task, (task) => task.user, { eager: true })
    tasks: Task[];
Enter fullscreen mode Exit fullscreen mode


import {
} from '@nestjs/common';
import { classToPlain, instanceToPlain } from 'class-transformer';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

export class TransformInterceptor implements NestInterceptor {
        context: ExecutionContext,
        next: CallHandler<any>,
    ): Observable<any> | Promise<Observabl
e<any>> {
        return next.handle().pipe(map((data) => instanceToPlain(data)));

Enter fullscreen mode Exit fullscreen mode


async function bootstrap() {
    const app = await NestFactory.create(AppModule);

    app.useGlobalPipes(new ValidationPipe());
    app.useGlobalInterceptors(new TransformInterceptor());

    await app.listen(3000);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)