Skip to content

Instantly share code, notes, and snippets.

View adsonrocha's full-sized avatar

Adson Rocha adsonrocha

View GitHub Profile
@adsonrocha
adsonrocha / posts.service.ts
Created February 21, 2020 13:21
ionic-offline-example-post-service-create
import {Injectable} from '@angular/core';
import {Storage} from '@ionic/storage';
import {of, Subject} from 'rxjs';
import {Post} from '../model/Post';
@Injectable({
providedIn: 'root'
})
export class PostsService {
@adsonrocha
adsonrocha / user.controller.ts
Last active October 23, 2019 00:41
User controller to call service with mongoose model injected
import { Body, Controller, Delete, Get, Param, Post, Put } from '@nestjs/common';
import { UserService } from './user.service';
import { User } from './user.model';
@Controller('user')
export class UserController {
constructor(private service: UserService) {
}
@Get('findById/:id')
@adsonrocha
adsonrocha / user.service.ts
Last active October 23, 2019 00:18
User service with mongoose model injected
import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { User } from './user.model';
import { Model } from 'mongoose';
@Injectable()
export class UserService {
constructor(
@InjectModel('User') private readonly userModel: Model<User>,
) {
@adsonrocha
adsonrocha / user.module.ts
Created October 22, 2019 23:37
User Module importing Mongoose
import { Module } from '@nestjs/common';
import { UserService } from './user.service';
import { UserController } from './user.controller';
import { MongooseModule } from '@nestjs/mongoose';
import { UserSchema } from './user.model';
@Module({
imports: [
MongooseModule.forFeature([{
name: 'User', schema: UserSchema,
@adsonrocha
adsonrocha / user.model.ts
Created October 22, 2019 23:18
Mongoose User Model and Interface
import * as mongoose from 'mongoose';
export const UserSchema = new mongoose.Schema({
name: { type: String, required: true },
age: { type: Number, required: true },
active: { type: Boolean, required: true },
});
export interface User {
id: string;
@adsonrocha
adsonrocha / app.module.ts
Last active October 22, 2019 22:50
Mongoose no NestJS
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UserModule } from './user/user.module';
import { MongooseModule } from '@nestjs/mongoose';
@Module({
imports: [
MongooseModule.forRoot('mongodb+srv://adsonrocha:<password>@cluster0-5efft.mongodb.net/test?retryWrites=true&w=majority'),
UserModule,
@adsonrocha
adsonrocha / index.js
Last active May 18, 2022 18:53
Como enviar e-mail usando Cloud Functions do Firebase com um projeto Ionic 3+ e Nodemailer
'use strict';
const functions = require('firebase-functions');
const nodemailer = require('nodemailer');
const cors = require('cors')({origin: true});
let url = "smtps://<SEU-EMAIL>%40gmail.com:"+encodeURIComponent('<SUA-SENHA>') + "@smtp.gmail.com:465";
let transporter = nodemailer.createTransport(url);
exports.enviarEmail = functions.https.onRequest((req, res) => {
cors(req, res, () => {
@adsonrocha
adsonrocha / FireBaseStorageComponent.ts
Created May 21, 2017 17:26
Firebase Storage with AngularFire2
import {Component} from '@angular/core';
import * as firebase from 'firebase';
@Component({
selector: 'my-component',
templateUrl: 'my-component.html'
})
export class FireBaseStorageComponent {
fbStorage: any;
fileName: string;