Skip to content

Instantly share code, notes, and snippets.

View davestacey's full-sized avatar

DaveStacey davestacey

View GitHub Profile
@davestacey
davestacey / 0-readme.md
Created February 23, 2020 01:03
passing async observable from container component to form component

async FormData$ passed to form from container. Form radio-group component using formcontrolname

@davestacey
davestacey / home.component.ts
Created February 21, 2020 15:55
CRUD component w logic for displaying the current user, list all users and deletion of users.
import { Component, OnInit } from '@angular/core';
import { first } from 'rxjs/operators';
import { User } from '@/_models';
import { UserService, AuthenticationService } from '@/_services';
@Component({ templateUrl: 'home.component.html' })
export class HomeComponent implements OnInit {
currentUser: User;
users = [];
@davestacey
davestacey / user.service.ts
Created February 21, 2020 15:43
User Service
/*
contains a standard set of CRUD methods for managing users,
*/
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { User } from '@/_models';
@Injectable({ providedIn: 'root' })
@davestacey
davestacey / authentication.service.ts
Created February 21, 2020 15:41
Authentication Service
/*
posts the users credentials to the api and checks the response for a JWT token, if there is one it means authentication was successful so the user details including the token are added to local storage.
The currentUser observable can be used when you want a component to reactively update when a user logs in or out
The currentUserValue property can be used when you just want to get the current value of the logged in user,checking if the user is currently logged in.
https://jasonwatmore.com/post/2019/06/10/angular-8-user-registration-and-login-example-tutorial
*/
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { BehaviorSubject, Observable } from 'rxjs';
@davestacey
davestacey / alert.service.ts
Last active September 16, 2021 19:19
Alert Service
/*
The alert service enables any component in the application to display alert messages at the top of the page via the alert component.
It has methods for displaying success and error messages, and a getMessage() method that returns an Observable that is used by the alert component to subscribe to notifications for whenever a message should be displayed.
https://jasonwatmore.com/post/2019/06/10/angular-8-user-registration-and-login-example-tutorial
*/
import { Injectable } from '@angular/core';
import { Router, NavigationStart } from '@angular/router';
import { Observable, Subject } from 'rxjs';
@davestacey
davestacey / jwt.interceptor.ts
Last active September 16, 2021 19:19
JWT Interceptor
import { Injectable } from '@angular/core';
import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor } from '@angular/common/http';
import { Observable } from 'rxjs';
import { AuthenticationService } from '@/_services';
@Injectable()
export class JwtInterceptor implements HttpInterceptor {
constructor(private authenticationService: AuthenticationService) {}
@davestacey
davestacey / error.interceptor.ts
Created February 21, 2020 14:37
Http Error Interceptor
/*
The Error Interceptor intercepts http responses from the api to check if there were any errors.
If there is a 401 Unauthorized response the user is automatically logged out of the application, all other errors are re-thrown up to the calling service so an alert can be displayed to the user.
*/
import { Injectable } from '@angular/core';
import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor } from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
@davestacey
davestacey / 00-readme.md
Created February 21, 2020 14:35
Fake Backend Provider
@davestacey
davestacey / 0-tap-demo.component.ts
Created July 13, 2019 17:57
RxJS 6.3.3 tap map etc
// use tap multiple times to debug values at different stages
of(1, 2, 3, 4).pipe(
tap(el => console.log(el)),
filter(n => n % 2 === 0),
tap(el => console.log(el)),
map(n => n + 10),
tap(el => console.log(el)),
scan((sum, n) => sum + n),
tap(el => console.log(el))
@davestacey
davestacey / 0_transferTablesFromStagingToProd.js
Last active May 28, 2023 16:54
backup Postgres To Local File
/**
* Build Roles
*/
let _ = require('lodash');
let transferTable = require('./transferTables_Util').transferTableFromStagingToProd;
// let tables = ['roles', 'permissions', 'role_permissions', 'nurture_triggers', 'nurture_chains', 'nurture_trigger_rules',
// 'account_api_keys', 'account_user_group_users', 'account_user_groups', 'account_users', 'users',