0% found this document useful (0 votes)
93 views3 pages

1.register - Service.ts:: Injectable Observable

The document describes an Angular application for user registration. 1. The RegisterService makes an HTTP POST request to register a user by calling the /User/register endpoint. 2. The RegisterComponent calls the RegisterService on form submit and displays an alert with the response message. 3. The server code creates Express apps for user and admin APIs, connects to a MongoDB database, and routes the /User/register endpoint to the UserAPI which inserts a new user or returns a message if they already exist.

Uploaded by

Chaitanya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views3 pages

1.register - Service.ts:: Injectable Observable

The document describes an Angular application for user registration. 1. The RegisterService makes an HTTP POST request to register a user by calling the /User/register endpoint. 2. The RegisterComponent calls the RegisterService on form submit and displays an alert with the response message. 3. The server code creates Express apps for user and admin APIs, connects to a MongoDB database, and routes the /User/register endpoint to the UserAPI which inserts a new user or returns a message if they already exist.

Uploaded by

Chaitanya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

/[Link].

ts:

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class RegisterService {

  constructor(private hc:HttpClient) { }

  doRegister(userobj):Observable<any>{
`    [Link](userobj);
   
      return [Link]('/User/register',userobj);
  }
}

[Link]:

import { Component, OnInit } from '@angular/core';
import { RegisterService } from '../[Link]';

@Component({
  selector: 'app-register',
  templateUrl: './[Link]',
  styleUrls: ['./[Link]']
})
export class RegisterComponent implements OnInit {

  constructor(private rs:RegisterService) { }

  ngOnInit() {
  }
    submitform(userobj)
    {
      [Link](userobj)
      [Link](userobj)
      .subscribe((data) =>{
        
           alert(data["message"]);
           
      })
    }
  }
[Link]:

/create express object
const exp=require("express")
const app=exp();
const path=require('path');
[Link]([Link]([Link](__dirname,'./dist/myap')))

// //import user and admin app
const userapp=require('./APIS/UserApi')
 const Adminapp=require('./APIS/AdminApi')

// //forward specific api
[Link]('/User',userapp)
[Link]('/Admin',Adminapp)
[Link](3000,()=>{
    [Link]("server is running");
})

[Link]

//create miniexpress app
const exp = require('express')

const mc=require("mongodb").MongoClient;
const UserExpressapp = [Link]()

[Link]([Link]())
var dbo;
const dburl="mongodb://admin:admin@cluster0-shard-00-00-
[Link],[Link],cluster0-
[Link]/test?ssl=true&replicaSet=Cluster0-shard-
0&authSource=admin&retryWrites=true&w=majority"
[Link](dburl,{useNewUrlParser:true,useUnifiedTopology:true},
(err,clientobj)=>{
    if(err){
        [Link]("err in db conn",err)
    }
    else{
        dbo=[Link]("empdb");
        [Link]("connected to db");
    }
});
[Link]('/register',(req, res) => {

    [Link]([Link])
    [Link]("empcollection").findOne({ Ename: [Link] }, (err, e
mpobj) => {
        if (err) {
            [Link]("err is occured ", err)
        }
        else if(empobj == null)
        {
            [Link]("empcollection").insertOne([Link], (err,success) 
=> 
            {
                if (err) 
                {
                    [Link]("err is occured", err)
                }
                else 
                {
                    [Link]({ message: "emp is created successfully" })
                }

            })
        }
        if(empobj!==null)
        {
            [Link]({ message: "emp is already created" })
        }
    })
})

[Link] = UserExpressapp;

You might also like