From b6163a7ecfd4e1edb6aba5feab14ab11c72d3ed8 Mon Sep 17 00:00:00 2001 From: Mosiur Date: Wed, 27 Nov 2024 01:28:57 +0600 Subject: [PATCH] Connected with DB and complted the Backup Service, Shift Update ongoin --- backend-server/src/index.ts | 79 ++++++++++++++++++- src/app/app.config.ts | 3 +- src/app/backup.ts | 14 +++- .../backup-list/backup-list.component.ts | 14 +++- .../pages/backup-list/backup-list.service.ts | 20 ++++- .../shift-update/shift-update.component.html | 3 +- .../shift-update/shift-update.component.ts | 33 ++++++-- .../pages/shift-update/update.service.ts | 20 ++++- .../input-form/input-form.component.html | 2 +- .../input-form/input-form.component.ts | 5 ++ src/app/shared/constants/backend.ts | 5 ++ src/app/shared/model/update.model.ts | 12 +-- 12 files changed, 179 insertions(+), 31 deletions(-) create mode 100644 src/app/shared/constants/backend.ts diff --git a/backend-server/src/index.ts b/backend-server/src/index.ts index 5a2cd3f..4818c65 100644 --- a/backend-server/src/index.ts +++ b/backend-server/src/index.ts @@ -6,9 +6,11 @@ import {vols} from "../../src/app/backup" const app = express() app.use(express.json()) +app.use(cors()) +const MONGO_URI = 'mongodb://jutsujen:f%40!ry-T%40!l@118.67.213.117:27017/navigatorDB?authSource=admin' -mongoose.connect('mongodb://jutsujen:f%40!ry-T%40!l@118.67.213.117:27017/navigatorDB?authMechanism=DEFAULT&tls=false').then(()=>{console.log("Connected")}).catch((err)=>console.log(err)) +mongoose.connect(MONGO_URI).then(()=>{console.log("Connected")}).catch((err)=>console.log(err)) const headerSchema = new mongoose.Schema({ headerName: String @@ -21,24 +23,93 @@ interface IBackup { volumeURL: string } +interface IUpdate { + Date: string, + Details: string, + Reference: string, + Remarks: string, + Sales: string, + Handler: string, + Status: string, + deleted: boolean +} + const backupSchema = new mongoose.Schema({ projectName: String, projectURL: String, volumeName: String, volumeURL: String +}, +{ + toJSON: { virtuals: true }, + toObject: { virtuals: true }, + timestamps: true, + }) + +const updateSchema = new mongoose.Schema({ + Date: String, + Details: String, + Reference: String, + Remarks: String, + Sales: String, + Handler: String, + Status: String, + deleted: { + type: Boolean, + default: false + }, +}, { + toJSON: {virtuals: true}, + toObject: {virtuals: true}, + timestamps: true, }) -const Backup = mongoose.model("backup",backupSchema) +const BackupModel = mongoose.model("backup",backupSchema) +const UpdateModel = mongoose.model("update", updateSchema) + app.get("/seed-backup", async (req,res)=>{ - const result = await Backup.insertMany(vols); - res.status(200).send(`Successfully seeded ${result.length} records.`); + // const backupCount = await BackupModel.countDocuments(); + // if (backupCount > 0) { + // res.send("Seed already done") + // } + BackupModel.create(vols) }) app.get("/", (req,res)=>{ res.send("Server Ran Properly") }) +app.get("/api/update", async (req,res)=>{ + const allUpdate = await UpdateModel.find({}).sort({ Date: 'asc' }) + res.status(200).send(allUpdate); +}) + +app.get("/api/backup", async (req,res)=>{ + const allBackup = await BackupModel.find({ deleted: { $ne: true} }).sort({ projectName: 'asc' }) + res.send(allBackup) +}) + +app.post("/api/update/add", async (req,res)=>{ + const {Date, Details, Reference, Remarks, Sales, Handler, Status, deleted} = req.body; + const newBackup = new UpdateModel({ + Date: Date, + Details: Details, + Reference: Reference, + Remarks: Remarks, + Sales: Sales, + Handler: Handler, + Status: Status, + deleted: deleted + }) + + await newBackup.save().then(()=>{ + res.status(201).json({ message: "Document saved successfully", success: true }) + }).catch((err)=> { + res.status(500).json({ error: err.message }); +}) +}) + const PORT = 3000; app.listen(PORT,()=>{ diff --git a/src/app/app.config.ts b/src/app/app.config.ts index a1e7d6f..94f5f50 100644 --- a/src/app/app.config.ts +++ b/src/app/app.config.ts @@ -2,7 +2,8 @@ import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core'; import { provideRouter } from '@angular/router'; import { routes } from './app.routes'; +import { provideHttpClient } from '@angular/common/http'; export const appConfig: ApplicationConfig = { - providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes)] + providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes), provideHttpClient()] }; diff --git a/src/app/backup.ts b/src/app/backup.ts index a139f3c..dbdcd53 100644 --- a/src/app/backup.ts +++ b/src/app/backup.ts @@ -130,5 +130,17 @@ export const vols = [ projectURL: "http://118.67.215.11/dashboard/auth/switch/e21290ae6e9845ddacb7158ba1d35867/?next=/dashboard/project/", volumeName: "Owncloud-Intercloud-VM-01-Vol-02-SAS", volumeURL: "http://118.67.215.11/dashboard/project/volumes/7dde4fc3-7a0e-4a5d-bca8-12fe6832d8d5/" - } + }, + { + projectName: "Revenue-Assurance", + projectURL: "http://118.67.215.11/dashboard/auth/switch/344358e7b22049a0bff2ac785417ab4e/?next=/dashboard/project/i", + volumeName: "revenue-assurence-VM-01-Vol-1", + volumeURL: "http://118.67.215.11/dashboard/project/volumes/76905062-4af5-405e-b485-3bd66d031a57/" + }, + { + projectName: "Revenue-Assurance", + projectURL: "http://118.67.215.11/dashboard/auth/switch/344358e7b22049a0bff2ac785417ab4e/?next=/dashboard/project/i", + volumeName: "revenue-assurence-VM-01-Vol-2", + volumeURL: "http://118.67.215.11/dashboard/project/volumes/f59c48b8-23c2-4f60-bc75-047d6363edc2/" + }, ] \ No newline at end of file diff --git a/src/app/components/pages/backup-list/backup-list.component.ts b/src/app/components/pages/backup-list/backup-list.component.ts index 6deb922..98e17cd 100644 --- a/src/app/components/pages/backup-list/backup-list.component.ts +++ b/src/app/components/pages/backup-list/backup-list.component.ts @@ -1,7 +1,8 @@ -import { Component, OnInit, ViewChild } from '@angular/core'; +import { Component, OnDestroy, OnInit } from '@angular/core'; import { BackupService } from './backup-list.service'; import { Backup } from '../../../shared/model/backup.model'; import { CommonModule } from '@angular/common'; +import { Subscription } from 'rxjs'; @Component({ selector: 'app-backup-list', @@ -11,14 +12,21 @@ import { CommonModule } from '@angular/common'; styleUrl: './backup-list.component.scss', providers: [BackupService] }) -export class BackupListComponent implements OnInit{ +export class BackupListComponent implements OnInit, OnDestroy{ backupVolumes: Backup[] = [] currentDate = new Date(); innerHTML!: string; + backupVolumesSubscription!: Subscription; constructor(private backupService: BackupService) {} ngOnInit(): void { - this.backupVolumes = this.backupService.allBackups; + this.backupVolumesSubscription = this.backupService.allBackups().subscribe((volumes)=>{ + this.backupVolumes = volumes; + }); + } + + ngOnDestroy(): void { + this.backupVolumesSubscription.unsubscribe(); } copyName(copyName: HTMLTableCellElement){ diff --git a/src/app/components/pages/backup-list/backup-list.service.ts b/src/app/components/pages/backup-list/backup-list.service.ts index c38203a..65365df 100644 --- a/src/app/components/pages/backup-list/backup-list.service.ts +++ b/src/app/components/pages/backup-list/backup-list.service.ts @@ -1,12 +1,24 @@ import { Injectable } from "@angular/core"; import { vols } from "../../../backup"; +import { HttpClient } from "@angular/common/http"; +import { Backup } from "../../../shared/model/backup.model"; +import { Observable } from "rxjs"; +import { BACKUP_GET_URL } from "../../../shared/constants/backend"; -Injectable({ - providedIn: 'root' +@Injectable({ + providedIn: 'root', }) + export class BackupService { - get allBackups() { - return vols + // get allBackups() { + // return vols + // } + private backupUrl = ''; + + constructor(private httpClient: HttpClient){} + + allBackups(): Observable { + return this.httpClient.get(BACKUP_GET_URL) } } \ No newline at end of file diff --git a/src/app/components/pages/shift-update/shift-update.component.html b/src/app/components/pages/shift-update/shift-update.component.html index a9a4175..018f92c 100644 --- a/src/app/components/pages/shift-update/shift-update.component.html +++ b/src/app/components/pages/shift-update/shift-update.component.html @@ -1,3 +1,4 @@ - + \ No newline at end of file diff --git a/src/app/components/pages/shift-update/shift-update.component.ts b/src/app/components/pages/shift-update/shift-update.component.ts index ec9a3be..97dbe48 100644 --- a/src/app/components/pages/shift-update/shift-update.component.ts +++ b/src/app/components/pages/shift-update/shift-update.component.ts @@ -1,10 +1,11 @@ -import { Component, EventEmitter, OnInit } from '@angular/core'; +import { Component, OnDestroy, OnInit } from '@angular/core'; +import { Subscription } from 'rxjs'; + import { TableComponent } from '../../../shared/components/table/table.component'; import { UpdateService } from './update.service'; import { TitleComponent } from '../../../shared/components/title/title.component'; -import { ShortenPipe } from '../../../shared/pipe/shorten.pipe'; import { InputFormComponent } from "../../../shared/components/input-form/input-form.component"; -import { BehaviorSubject } from 'rxjs'; +import { Update } from '../../../shared/model/update.model'; @Component({ selector: 'app-shift-update', @@ -14,24 +15,40 @@ import { BehaviorSubject } from 'rxjs'; styleUrl: './shift-update.component.scss', providers: [UpdateService] }) -export class ShiftUpdateComponent implements OnInit { +export class ShiftUpdateComponent implements OnInit, OnDestroy { tableHeaderList = ['Date','Details','Remarks','Sales','Reference','Handler', 'Status'] - updateDataList: any[] = []; - + updateDataList: Update[] = []; + updateListSubscription!: Subscription; constructor(private updateService: UpdateService) {} ngOnInit(): void { - this.updateDataList = this.updateService.allUpdate; + this.updateListSubscription = this.updateService.allUpdate().subscribe((update)=>{ + this.updateDataList = update; + console.log(this.updateDataList.keys) + }); console.log(this.completeTask) } + ngOnDestroy(): void { + this.updateListSubscription.unsubscribe(); + } + completeTask(event: string) { - console.log(event) + // } deleteTask(event: boolean) { + // + } + addUpdate(newUpdate:any){ + this.updateService.addUpdate(newUpdate); + } + onClick(){ + this.updateService.allUpdate().subscribe((update)=>{ + this.updateDataList = update; + }) } } diff --git a/src/app/components/pages/shift-update/update.service.ts b/src/app/components/pages/shift-update/update.service.ts index 987e3da..4efae4f 100644 --- a/src/app/components/pages/shift-update/update.service.ts +++ b/src/app/components/pages/shift-update/update.service.ts @@ -1,13 +1,27 @@ import { Injectable } from "@angular/core"; import { sample_update } from "./sample_update"; +import { Observable } from "rxjs"; +import { Update } from "../../../shared/model/update.model"; +import { HttpClient } from "@angular/common/http"; +import { UPDATE_ADD_URL, UPDATE_GET_URL } from "../../../shared/constants/backend"; -Injectable({ +@Injectable({ providedIn: 'root' }) export class UpdateService{ - get allUpdate(){ - return sample_update; + + constructor(private httpClient: HttpClient){} + + allUpdate() { + return this.httpClient.get(UPDATE_GET_URL) + } + + addUpdate(newUpdate: Update) { + newUpdate.deleted = false; + this.httpClient.post(UPDATE_ADD_URL,newUpdate).subscribe((log)=>{ + console.log(log) + }) } } diff --git a/src/app/shared/components/input-form/input-form.component.html b/src/app/shared/components/input-form/input-form.component.html index ce391cf..5cc5d6f 100644 --- a/src/app/shared/components/input-form/input-form.component.html +++ b/src/app/shared/components/input-form/input-form.component.html @@ -7,7 +7,7 @@
- +
diff --git a/src/app/shared/components/input-form/input-form.component.ts b/src/app/shared/components/input-form/input-form.component.ts index 4d91aa8..7cee755 100644 --- a/src/app/shared/components/input-form/input-form.component.ts +++ b/src/app/shared/components/input-form/input-form.component.ts @@ -14,6 +14,7 @@ export class InputFormComponent { @Output() formValues: EventEmitter<{}> = new EventEmitter<{}>(); formData: {[key: string]: string} = {} @Input() isFormVisible: boolean = false; + @Output() clicked: EventEmitter = new EventEmitter() onSubmit(formData: NgForm){ this.formValues.emit(formData.value) @@ -21,4 +22,8 @@ export class InputFormComponent { toggleForm() { this.isFormVisible = !this.isFormVisible; } + + onClick(){ + this.clicked.emit() + } } diff --git a/src/app/shared/constants/backend.ts b/src/app/shared/constants/backend.ts new file mode 100644 index 0000000..bee476c --- /dev/null +++ b/src/app/shared/constants/backend.ts @@ -0,0 +1,5 @@ +const MAIN_URL = "http://localhost:3000/api" + +export const BACKUP_GET_URL = `${MAIN_URL}/backup`; +export const UPDATE_GET_URL = `${MAIN_URL}/update`; +export const UPDATE_ADD_URL = `${UPDATE_GET_URL}/add` \ No newline at end of file diff --git a/src/app/shared/model/update.model.ts b/src/app/shared/model/update.model.ts index 00a9791..0559aed 100644 --- a/src/app/shared/model/update.model.ts +++ b/src/app/shared/model/update.model.ts @@ -1,9 +1,11 @@ export class Update{ id!: string; - date!: string; - details!: string; - remarks!: string; + Date!: string; + Details!: string; + Remarks!: string; Sales_Concern!: string; - reference!: string; - handler!: string; + Reference!: string; + Handler!: string; + Status!: string; + deleted!: Boolean; } \ No newline at end of file