Skip to content

Instantly share code, notes, and snippets.

View kasir-barati's full-sized avatar
Dedicated to achieve his goals

Mohammad Jawad (Kasir) Barati kasir-barati

Dedicated to achieve his goals
View GitHub Profile
const { DataTypes, Model } = require("sequelize");
const sequelize = require("../sequelize");
class Role extends Model {
static col = {
id: "id",
name: "name",
};
static alias = {
const { DataTypes, Model } = require("sequelize");
const Role = require("./role");
const sequelize = require("../sequelize");
class User extends Model {
static col = {
id: "id",
name: "name",
roleId: "roleId",
const { DataTypes, Model } = require("sequelize");
const sequelize = require("../sequelize");
class Order extends Model {
static col = {
id: "id",
name: "name",
};
static alias = {
const { DataTypes, Model } = require("sequelize");
const sequelize = require("../sequelize");
const Order = require("./order");
class Payment extends Model {
static col = {
id: "id",
refId: "refId",
orderId: "orderId",
const sequelize = require("../sequelize");
const Order = require("./order");
const Payment = require("./payment");
sequelize
.getSeq()
.sync({ force: true })
.then(async () => {
// queries
@kasir-barati
kasir-barati / traefik.yml
Created April 8, 2022 06:09
Traefik compose file
log:
level: DEBUG
filepath: "/etc/traefik/log/traefik.log"
api:
dashboard: true
insecure: false
debug: true
# Define ports - UDP or TCP - which will recieve packets
entryPoints:
@kasir-barati
kasir-barati / many-to-many.prisma
Last active April 9, 2022 05:53
relationships in prisma linkedin
// This is your Prisma schema file
// learn more about it in the docs: https://pris.ly/d/prisma-schema
// N:M relationship in prisma
datasource db {
provider = "postgres"
url = env("DATABASE_URL")
}
generator client {
@kasir-barati
kasir-barati / app.module.ts
Created April 14, 2022 10:12
Global throttler, Throttler behind the proxy with custom message in nestjs
import { Module } from '@nestjs/common';
import { ThrottlerModule } from '@nestjs/throttler';
import { ThrottlerStorageRedisService } from 'nestjs-throttler-storage-redis';
import { AppService } from './service/app.service';
import { AppController } from './app.controller';
import { APP_GUARD } from '@nestjs/core';
import { GlobalThrottlerGuard } from './guards/global-throttler.guard';
@Module({
@kasir-barati
kasir-barati / main.sh
Last active April 20, 2022 11:26
Postgresql: dump, restore, connect to it, etc
# Connect to postgres
PGPASSWORD="pass" psql -h localhost -p 5432 -U user -d db-name
# You can also use .pgpass, TBH it does not work in my experience. BTW this is much much safer from point of security - No track in terminal history.
touch ~/.pgpass
# Replace its values:
db_host:db_port:db_name:db_user:db_pass
# Dump from postgres
# Doc: https://www.postgresql.org/docs/14/app-pgdump.html
@kasir-barati
kasir-barati / auto-generated-prisma-client.ts
Created May 1, 2022 13:14
Custom DTO for validating date
export const FlightRegionType: {
DOMESTIC: 'DOMESTIC',
INTERNATIONAL: 'INTERNATIONAL'
};
export const CabinClass: {
ECONOMY: 'ECONOMY',
BUSINESS: 'BUSINESS',
FIRST: 'FIRST'
};