build a backend with typescript using nest js
play

Build a backend with TypeScript using Nest.js RICHARD MOOT - PowerPoint PPT Presentation

Build a backend with TypeScript using Nest.js RICHARD MOOT DEVELOPER EVANGELIST @ SQUARE What is NestJS? A progressive Node.js framework for building efficient, reliable and scalable server-side applications. Huh? Nest provides an


  1. Build a backend with TypeScript using Nest.js RICHARD MOOT DEVELOPER EVANGELIST @ SQUARE

  2. What is NestJS? A progressive Node.js framework for building efficient, reliable and scalable server-side applications. Huh? Nest provides an out-of-the-box application architecture which allows developers and teams to create highly testable, scalable, loosely coupled, and easily maintainable applications. � 3

  3. How is this different that just using Express? Fully supports TypeScript - Structured (similar to Angular) - Extremely modular - Supports dependency injection - Platform agnostic - GraphQL, microservices, CLI, and OpenAPI support - � 4

  4. What does a Nest app look like? $ npm i -g @nestjs/cli $ nest new project-name � 5

  5. app.module.ts � 6

  6. app.service.ts � 7

  7. app.controller.ts � 8

  8. main.ts � 9

  9. Real App Time – Order Ahead � 10

  10. square.service.ts � 11

  11. import { Injectable } from '@nestjs/common'; import { ConfigService } from '../config/config.service'; import * as SquareConnect from 'square-connect'; import { randomBytes } from 'crypto'; import { PaymentDto } from './dto/PaymentDto.dto'; import * as functions from 'firebase-functions'; @Injectable() export class SquareService { constructor(config: ConfigService) { this.accessToken = config.get("ACCESS_TOKEN"); const SquareClient = SquareConnect.ApiClient.instance; const oauth2 = SquareClient.authentications["oauth2"]; oauth2.accessToken = this.accessToken; Footnote � 12 } private accessToken: string;

  12. import { Injectable } from '@nestjs/common'; import { ConfigService } from '../config/config.service'; import * as SquareConnect from 'square-connect'; import { randomBytes } from 'crypto'; import { PaymentDto } from './dto/PaymentDto.dto'; import * as functions from 'firebase-functions'; @Injectable() export class SquareService { constructor(config: ConfigService) { this.accessToken = config.get("ACCESS_TOKEN"); const SquareClient = SquareConnect.ApiClient.instance; const oauth2 = SquareClient.authentications["oauth2"]; oauth2.accessToken = this.accessToken; Footnote � 13 } private accessToken: string;

  13. import { Injectable } from '@nestjs/common'; import { ConfigService } from '../config/config.service'; import * as SquareConnect from 'square-connect'; import { randomBytes } from 'crypto'; import { PaymentDto } from './dto/PaymentDto.dto'; import * as functions from 'firebase-functions'; @Injectable() export class SquareService { constructor(config: ConfigService) { this.accessToken = config.get("ACCESS_TOKEN"); const SquareClient = SquareConnect.ApiClient.instance; const oauth2 = SquareClient.authentications["oauth2"]; oauth2.accessToken = this.accessToken; Footnote � 14 } private accessToken: string;

  14. import { randomBytes } from 'crypto'; import { PaymentDto } from './dto/PaymentDto.dto'; import * as functions from 'firebase-functions'; @Injectable() export class SquareService { constructor(config: ConfigService) { this.accessToken = config.get("ACCESS_TOKEN"); const SquareClient = SquareConnect.ApiClient.instance; const oauth2 = SquareClient.authentications["oauth2"]; oauth2.accessToken = this.accessToken; } private accessToken: string; async pay(paymentRequest: PaymentDto){ const locationsApi = new SquareConnect.LocationsApi(); const transactionsApi = new SquareConnect.TransactionsApi(); const ordersApi = new SquareConnect.OrdersApi(); � 15 const { locations } = await locationsApi.listLocations();

  15. import { randomBytes } from 'crypto'; import { PaymentDto } from './dto/PaymentDto.dto'; import * as functions from 'firebase-functions'; @Injectable() export class SquareService { constructor(config: ConfigService) { this.accessToken = config.get("ACCESS_TOKEN"); const SquareClient = SquareConnect.ApiClient.instance; const oauth2 = SquareClient.authentications["oauth2"]; oauth2.accessToken = this.accessToken; } private accessToken: string; async pay(paymentRequest: PaymentDto){ const locationsApi = new SquareConnect.LocationsApi(); const transactionsApi = new SquareConnect.TransactionsApi(); const ordersApi = new SquareConnect.OrdersApi(); � 16 const { locations } = await locationsApi.listLocations();

  16. import { randomBytes } from 'crypto'; import { PaymentDto } from './dto/PaymentDto.dto'; import * as functions from 'firebase-functions'; @Injectable() export class SquareService { constructor(config: ConfigService) { this.accessToken = config.get("ACCESS_TOKEN"); const SquareClient = SquareConnect.ApiClient.instance; const oauth2 = SquareClient.authentications["oauth2"]; oauth2.accessToken = this.accessToken; } private accessToken: string; async pay(paymentRequest: PaymentDto){ const locationsApi = new SquareConnect.LocationsApi(); const transactionsApi = new SquareConnect.TransactionsApi(); const ordersApi = new SquareConnect.OrdersApi(); � 17 const { locations } = await locationsApi.listLocations();

  17. import { randomBytes } from 'crypto'; import { PaymentDto } from './dto/PaymentDto.dto'; import * as functions from 'firebase-functions'; @Injectable() export class SquareService { constructor(config: ConfigService) { this.accessToken = config.get("ACCESS_TOKEN"); const SquareClient = SquareConnect.ApiClient.instance; const oauth2 = SquareClient.authentications["oauth2"]; oauth2.accessToken = this.accessToken; } private accessToken: string; async pay(paymentRequest: PaymentDto){ const locationsApi = new SquareConnect.LocationsApi(); const transactionsApi = new SquareConnect.TransactionsApi(); const ordersApi = new SquareConnect.OrdersApi(); � 18 const { locations } = await locationsApi.listLocations();

  18. private accessToken: string; async pay(paymentRequest: PaymentDto){ const locationsApi = new SquareConnect.LocationsApi(); const transactionsApi = new SquareConnect.TransactionsApi(); const ordersApi = new SquareConnect.OrdersApi(); const { locations } = await locationsApi.listLocations(); const locationId = locations[0].id; try { const { order } = await ordersApi.createOrder(locationId, { idempotency_key: randomBytes(48).toString('hex'), order: { line_items: [ { quantity: '1', catalog_object_id: paymentRequest.item.variations[0].id, Footnote � 19 } ],

  19. private accessToken: string; async pay(paymentRequest: PaymentDto){ const locationsApi = new SquareConnect.LocationsApi(); const transactionsApi = new SquareConnect.TransactionsApi(); const ordersApi = new SquareConnect.OrdersApi(); const { locations } = await locationsApi.listLocations(); const locationId = locations[0].id; try { const { order } = await ordersApi.createOrder(locationId, { idempotency_key: randomBytes(48).toString('hex'), order: { line_items: [ { quantity: '1', catalog_object_id: paymentRequest.item.variations[0].id, Footnote � 20 } ],

  20. private accessToken: string; async pay(paymentRequest: PaymentDto){ const locationsApi = new SquareConnect.LocationsApi(); const transactionsApi = new SquareConnect.TransactionsApi(); const ordersApi = new SquareConnect.OrdersApi(); const { locations } = await locationsApi.listLocations(); const locationId = locations[0].id; try { const { order } = await ordersApi.createOrder(locationId, { idempotency_key: randomBytes(48).toString('hex'), order: { line_items: [ { quantity: '1', catalog_object_id: paymentRequest.item.variations[0].id, Footnote � 21 } ],

  21. private accessToken: string; async pay(paymentRequest: PaymentDto){ const locationsApi = new SquareConnect.LocationsApi(); const transactionsApi = new SquareConnect.TransactionsApi(); const ordersApi = new SquareConnect.OrdersApi(); const { locations } = await locationsApi.listLocations(); const locationId = locations[0].id; try { const { order } = await ordersApi.createOrder(locationId, { idempotency_key: randomBytes(48).toString('hex'), order: { line_items: [ { quantity: '1', catalog_object_id: paymentRequest.item.variations[0].id, Footnote � 22 } ],

  22. const locationId = locations[0].id; try { const { order } = await ordersApi.createOrder(locationId, { idempotency_key: randomBytes(48).toString('hex'), order: { line_items: [ { quantity: '1', catalog_object_id: paymentRequest.item.variations[0].id, } ], fulfillments: [ { type: 'PICKUP', state: 'PROPOSED', pickup_details: { recipient: { Footnote � 23 display_name: paymentRequest.customer.name, email: paymentRequest.customer.email

  23. const locationId = locations[0].id; try { const { order } = await ordersApi.createOrder(locationId, { idempotency_key: randomBytes(48).toString('hex'), order: { line_items: [ { quantity: '1', catalog_object_id: paymentRequest.item.variations[0].id, } ], fulfillments: [ { type: 'PICKUP', state: 'PROPOSED', pickup_details: { recipient: { Footnote � 24 display_name: paymentRequest.customer.name, email: paymentRequest.customer.email

  24. const locationId = locations[0].id; try { const { order } = await ordersApi.createOrder(locationId, { idempotency_key: randomBytes(48).toString('hex'), order: { line_items: [ { quantity: '1', catalog_object_id: paymentRequest.item.variations[0].id, } ], fulfillments: [ { type: 'PICKUP', state: 'PROPOSED', pickup_details: { recipient: { Footnote � 25 display_name: paymentRequest.customer.name, email: paymentRequest.customer.email

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend