Connected with DB and complted the Backup Service, Shift Update ongoin

This commit is contained in:
Mosiur
2024-11-27 01:28:57 +06:00
parent ceacc20f68
commit b6163a7ecf
12 changed files with 179 additions and 31 deletions

View File

@@ -6,9 +6,11 @@ import {vols} from "../../src/app/backup"
const app = express() const app = express()
app.use(express.json()) 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({ const headerSchema = new mongoose.Schema({
headerName: String headerName: String
@@ -21,24 +23,93 @@ interface IBackup {
volumeURL: string 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<IBackup>({ const backupSchema = new mongoose.Schema<IBackup>({
projectName: String, projectName: String,
projectURL: String, projectURL: String,
volumeName: String, volumeName: String,
volumeURL: String volumeURL: String
},
{
toJSON: { virtuals: true },
toObject: { virtuals: true },
timestamps: true,
})
const updateSchema = new mongoose.Schema<IUpdate>({
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<IBackup>("backup",backupSchema) const BackupModel = mongoose.model<IBackup>("backup",backupSchema)
const UpdateModel = mongoose.model<IUpdate>("update", updateSchema)
app.get("/seed-backup", async (req,res)=>{ app.get("/seed-backup", async (req,res)=>{
const result = await Backup.insertMany(vols); // const backupCount = await BackupModel.countDocuments();
res.status(200).send(`Successfully seeded ${result.length} records.`); // if (backupCount > 0) {
// res.send("Seed already done")
// }
BackupModel.create(vols)
}) })
app.get("/", (req,res)=>{ app.get("/", (req,res)=>{
res.send("Server Ran Properly") 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; const PORT = 3000;
app.listen(PORT,()=>{ app.listen(PORT,()=>{

View File

@@ -2,7 +2,8 @@ import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
import { provideRouter } from '@angular/router'; import { provideRouter } from '@angular/router';
import { routes } from './app.routes'; import { routes } from './app.routes';
import { provideHttpClient } from '@angular/common/http';
export const appConfig: ApplicationConfig = { export const appConfig: ApplicationConfig = {
providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes)] providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes), provideHttpClient()]
}; };

View File

@@ -130,5 +130,17 @@ export const vols = [
projectURL: "http://118.67.215.11/dashboard/auth/switch/e21290ae6e9845ddacb7158ba1d35867/?next=/dashboard/project/", projectURL: "http://118.67.215.11/dashboard/auth/switch/e21290ae6e9845ddacb7158ba1d35867/?next=/dashboard/project/",
volumeName: "Owncloud-Intercloud-VM-01-Vol-02-SAS", volumeName: "Owncloud-Intercloud-VM-01-Vol-02-SAS",
volumeURL: "http://118.67.215.11/dashboard/project/volumes/7dde4fc3-7a0e-4a5d-bca8-12fe6832d8d5/" 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/"
},
] ]

View File

@@ -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 { BackupService } from './backup-list.service';
import { Backup } from '../../../shared/model/backup.model'; import { Backup } from '../../../shared/model/backup.model';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { Subscription } from 'rxjs';
@Component({ @Component({
selector: 'app-backup-list', selector: 'app-backup-list',
@@ -11,14 +12,21 @@ import { CommonModule } from '@angular/common';
styleUrl: './backup-list.component.scss', styleUrl: './backup-list.component.scss',
providers: [BackupService] providers: [BackupService]
}) })
export class BackupListComponent implements OnInit{ export class BackupListComponent implements OnInit, OnDestroy{
backupVolumes: Backup[] = [] backupVolumes: Backup[] = []
currentDate = new Date(); currentDate = new Date();
innerHTML!: string; innerHTML!: string;
backupVolumesSubscription!: Subscription;
constructor(private backupService: BackupService) {} constructor(private backupService: BackupService) {}
ngOnInit(): void { 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){ copyName(copyName: HTMLTableCellElement){

View File

@@ -1,12 +1,24 @@
import { Injectable } from "@angular/core"; import { Injectable } from "@angular/core";
import { vols } from "../../../backup"; 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({ @Injectable({
providedIn: 'root' providedIn: 'root',
}) })
export class BackupService { export class BackupService {
get allBackups() { // get allBackups() {
return vols // return vols
// }
private backupUrl = '';
constructor(private httpClient: HttpClient){}
allBackups(): Observable<Backup[]> {
return this.httpClient.get<Backup[]>(BACKUP_GET_URL)
} }
} }

View File

@@ -1,3 +1,4 @@
<page-title title="Shift Update"></page-title> <page-title title="Shift Update"></page-title>
<app-input-form [fields]="tableHeaderList"></app-input-form> <app-input-form [fields]="tableHeaderList" (formValues)="addUpdate($event)"
(clicked)="onClick()"></app-input-form>
<app-table [tableHeaders]="tableHeaderList" [rowDataList]="updateDataList" (complete)="completeTask($event)" (delete)="deleteTask($event)"></app-table> <app-table [tableHeaders]="tableHeaderList" [rowDataList]="updateDataList" (complete)="completeTask($event)" (delete)="deleteTask($event)"></app-table>

View File

@@ -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 { TableComponent } from '../../../shared/components/table/table.component';
import { UpdateService } from './update.service'; import { UpdateService } from './update.service';
import { TitleComponent } from '../../../shared/components/title/title.component'; 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 { InputFormComponent } from "../../../shared/components/input-form/input-form.component";
import { BehaviorSubject } from 'rxjs'; import { Update } from '../../../shared/model/update.model';
@Component({ @Component({
selector: 'app-shift-update', selector: 'app-shift-update',
@@ -14,24 +15,40 @@ import { BehaviorSubject } from 'rxjs';
styleUrl: './shift-update.component.scss', styleUrl: './shift-update.component.scss',
providers: [UpdateService] providers: [UpdateService]
}) })
export class ShiftUpdateComponent implements OnInit { export class ShiftUpdateComponent implements OnInit, OnDestroy {
tableHeaderList = ['Date','Details','Remarks','Sales','Reference','Handler', 'Status'] tableHeaderList = ['Date','Details','Remarks','Sales','Reference','Handler', 'Status']
updateDataList: any[] = []; updateDataList: Update[] = [];
updateListSubscription!: Subscription;
constructor(private updateService: UpdateService) {} constructor(private updateService: UpdateService) {}
ngOnInit(): void { 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) console.log(this.completeTask)
} }
ngOnDestroy(): void {
this.updateListSubscription.unsubscribe();
}
completeTask(event: string) { completeTask(event: string) {
console.log(event) //
} }
deleteTask(event: boolean) { deleteTask(event: boolean) {
//
}
addUpdate(newUpdate:any){
this.updateService.addUpdate(newUpdate);
}
onClick(){
this.updateService.allUpdate().subscribe((update)=>{
this.updateDataList = update;
})
} }
} }

View File

@@ -1,13 +1,27 @@
import { Injectable } from "@angular/core"; import { Injectable } from "@angular/core";
import { sample_update } from "./sample_update"; 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' providedIn: 'root'
}) })
export class UpdateService{ export class UpdateService{
get allUpdate(){
return sample_update; constructor(private httpClient: HttpClient){}
allUpdate() {
return this.httpClient.get<Update[]>(UPDATE_GET_URL)
}
addUpdate(newUpdate: Update) {
newUpdate.deleted = false;
this.httpClient.post(UPDATE_ADD_URL,newUpdate).subscribe((log)=>{
console.log(log)
})
} }
} }

View File

@@ -7,7 +7,7 @@
<input class="form-control" type="text" [id]="field" [name]="field" [(ngModel)]="formData[field]" [placeholder]="'enter '+field" required> <input class="form-control" type="text" [id]="field" [name]="field" [(ngModel)]="formData[field]" [placeholder]="'enter '+field" required>
</div> </div>
<div class="btn"> <div class="btn">
<button [disabled]="inputForm.invalid">Submit</button> <button [disabled]="inputForm.invalid" (click)="onClick()">Submit</button>
</div> </div>
</div> </div>
</form> </form>

View File

@@ -14,6 +14,7 @@ export class InputFormComponent {
@Output() formValues: EventEmitter<{}> = new EventEmitter<{}>(); @Output() formValues: EventEmitter<{}> = new EventEmitter<{}>();
formData: {[key: string]: string} = {} formData: {[key: string]: string} = {}
@Input() isFormVisible: boolean = false; @Input() isFormVisible: boolean = false;
@Output() clicked: EventEmitter<void> = new EventEmitter<void>()
onSubmit(formData: NgForm){ onSubmit(formData: NgForm){
this.formValues.emit(formData.value) this.formValues.emit(formData.value)
@@ -21,4 +22,8 @@ export class InputFormComponent {
toggleForm() { toggleForm() {
this.isFormVisible = !this.isFormVisible; this.isFormVisible = !this.isFormVisible;
} }
onClick(){
this.clicked.emit()
}
} }

View File

@@ -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`

View File

@@ -1,9 +1,11 @@
export class Update{ export class Update{
id!: string; id!: string;
date!: string; Date!: string;
details!: string; Details!: string;
remarks!: string; Remarks!: string;
Sales_Concern!: string; Sales_Concern!: string;
reference!: string; Reference!: string;
handler!: string; Handler!: string;
Status!: string;
deleted!: Boolean;
} }