Refactor request service
- Add http post and postgraphql methods to base servicemaster
parent
99f1a315ef
commit
76adff40eb
@ -1,12 +0,0 @@
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
|
||||
import {DocumentService} from './document.service';
|
||||
|
||||
describe('DocumentService', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({}));
|
||||
|
||||
it('should be created', () => {
|
||||
const service: DocumentService = TestBed.get(DocumentService);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
@ -1,39 +0,0 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
|
||||
import {Socket} from 'ngx-socket-io';
|
||||
|
||||
import {Document} from '../models/document';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class DocumentService {
|
||||
currentDocument = this.socket.fromEvent<Document>('document');
|
||||
documents = this.socket.fromEvent<string[]>('documents');
|
||||
|
||||
constructor(private socket: Socket) {
|
||||
}
|
||||
|
||||
getDocument(id: string) {
|
||||
this.socket.emit('getDoc', id);
|
||||
}
|
||||
|
||||
newDocument() {
|
||||
this.socket.emit('addDoc', {id: this.docId(), doc: ''});
|
||||
}
|
||||
|
||||
editDocument(document: Document) {
|
||||
this.socket.emit('editDoc', document);
|
||||
}
|
||||
|
||||
private docId() {
|
||||
let text = '';
|
||||
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
|
||||
for (let i = 0; i < 5; i++) {
|
||||
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue