View transaction-example.ts
@Post('money/transfer') | |
async transferMoney(@Body() dto: TransferMoneyDto) { | |
// Start session using mongo connection | |
const session = await this.mongoConnection.startSession(); | |
// Start transaction using the session | |
session.startTransaction(); | |
try { | |
// This method will do a few mongo db operations | |
const result = await this.transferMoneyService.transfer(dto, session); |
View azure-service-bus.ts
import { Injectable } from '@nestjs/common'; | |
import { ReceiveMode, ServiceBusClient } from '@azure/service-bus'; | |
@Injectable() | |
export class ServiceBusService { | |
constructor() { | |
this.init(); | |
} | |
async init() { |
View reduxjs-toolkit-example.ts
import { createSlice, PayloadAction } from '@reduxjs/toolkit'; | |
import { UserProfileApi, UserSettingsApi } from '@selfplat/api-model'; | |
import { AppThunk } from '../root.store'; | |
import { ProfileService } from './profile.service'; | |
export interface UserState { | |
profile: UserProfileApi; | |
settings: UserSettingsApi; | |
} |
View theme.ts
const theme = { | |
breakpoints: ['30em', '48em', '62em', '80em'], | |
zIndices: { | |
hide: -1, | |
auto: 'auto', | |
base: 0, | |
docked: 10, | |
dropdown: 1000, | |
sticky: 1100, | |
banner: 1200, |
View palindrom.js
//Make the following test cases pass | |
function isPalindrome(phrase) { | |
const SPACE = " "; | |
const lowerCharsInPhrase = phrase | |
.toLowerCase() | |
.split("") | |
.filter(char => char !== SPACE); | |
return lowerCharsInPhrase.join() === lowerCharsInPhrase.reverse().join(); | |
} |
View optional-operator.ts
const maybePerson = getPerson(); | |
console.log(maybePerson?.name); | |
console.log(maybePerson?.name?.firstName); | |
console.log(maybePerson?.name?.lastName); | |
console.log(maybePerson?.name?.getFullName?.()); |
View handle-with-if.ts
const maybePerson = getPerson(); | |
if (maybePerson) { | |
console.log(maybePerson.name); | |
} | |
if (maybePerson && maybePerson.name) { | |
console.log(maybePerson.name.firstName); | |
console.log(maybePerson.name.lastName); | |
} |
View getPerson.ts
function getRandomNumber() { | |
return Math.floor(Math.random() * 100); | |
} | |
function isEvenNumber(number: number) { | |
return number % 2 == 0; | |
} | |
function getPerson() { | |
if (isEvenNumber(getRandomNumber())) { |
View unsubscribe-02.ts
export class AppComponent implements OnInit, OnDestroy { | |
@Selector(CustomersState.SelectedCustomer) | |
private selectedCustomer$: Observable<Customer>; | |
@Selector(OrdersState.NewOrder) | |
private newOrder$: Observable<Order>; | |
private onComponentDestroy$: Subject<void>; | |
constructor() { |
View unsubscribe-01.ts
import { Component, OnDestroy, OnInit } from '@angular/core'; | |
import { Observable, Subscription } from 'rxjs'; | |
export class RxJSUtil { | |
static unsubscribe = (subscriptions: Subscription[]) => | |
subscriptions.forEach(subscription => subscription.unsubscribe()); | |
} | |
@Component({ | |
selector: 'nx-tutorial-root', |
NewerOlder