This file contains hidden or 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
| import { Request, Response } from 'express'; | |
| import GetAllUsers from './getAllUsers'; | |
| describe('Get all users request', () => { | |
| let mockRequest: Partial<Request>; | |
| let mockResponse: Partial<Response>; | |
| let responseObject = {}; | |
| beforeEach(() => { | |
| mockRequest = { |
This file contains hidden or 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
| const express = require('express'); | |
| const router = express.Router(); | |
| router.get('/excel/example', (request, response) => { | |
| response.download('./excelFiles/foods.xlsx', 'example.xlsx'); | |
| }); | |
| module.exports = router; |
This file contains hidden or 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
| export type User = { | |
| name: string, | |
| age: number, | |
| roles: Role[]; | |
| } | |
| export function isValidUser(user: unknown): user is User { | |
| return !!(user as User).name && | |
| !!(user as User).age && | |
| !!(user as User).roles && |
This file contains hidden or 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
| type User = { | |
| name: string, | |
| age: number, | |
| roles: Role[]; | |
| } | |
| type Role = { | |
| label: string | |
| } |
This file contains hidden or 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
| const xlsx = require('xlsx'); | |
| const path = require('path'); | |
| const exportExcel = (data, workSheetColumnNames, workSheetName, filePath) => { | |
| const workBook = xlsx.utils.book_new(); | |
| const workSheetData = [ | |
| workSheetColumnNames, | |
| ... data | |
| ]; | |
| const workSheet = xlsx.utils.aoa_to_sheet(workSheetData); |
This file contains hidden or 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
| const validateUser = (user) ⇒ { | |
| return user.name === undefined; | |
| } | |
| // OR | |
| const validateUser = (user) ⇒ user.name === undefined; | |
| // OR |
This file contains hidden or 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
| import "reflect-metadata"; | |
| import {createConnection, ConnectionOptions} from "typeorm"; | |
| import http from "http"; | |
| import express from 'express'; | |
| import config from "../ormconfig.json"; | |
| import GetAllUsers from "./controllers/GetAllUsers"; | |
| createConnection(config as ConnectionOptions).then(async connection => { | |
| const app = express(); | |
| app.use(express.json()); |
This file contains hidden or 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
| import {Request, Response} from 'express'; | |
| import {getCustomRepository} from "typeorm"; | |
| import {UserRepository} from "../db/repositories/UserRepository"; | |
| const GetAllUsers = async (request: Request, response: Response) => { | |
| const userRepository = getCustomRepository(UserRepository); | |
| const users = await userRepository.find(); | |
| response.json({ users }); | |
| } |
This file contains hidden or 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
| import {EntitySubscriberInterface, EventSubscriber, InsertEvent} from "typeorm"; | |
| import {User} from "../entities/User"; | |
| @EventSubscriber() | |
| export class UserSubscriber implements EntitySubscriberInterface<User> { | |
| listenTo() { | |
| return User; | |
| } | |
| beforeInsert(event: InsertEvent<User>) { |
This file contains hidden or 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
| import {EntityRepository, Repository} from "typeorm"; | |
| import {User} from "../entities/User"; | |
| @EntityRepository(User) | |
| export class UserRepository extends Repository<User> { | |
| findByName(name: string) { | |
| return this.findOne({ name }); | |
| } | |
| } |