2018-10-12 11:05:24 +02:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { DataSendService } from '../../../core/services/data-send.service';
|
|
|
|
import { DataStoreService } from '../../../core/services/data-store.service';
|
|
|
|
import { BaseRepository } from '../../base/base-repository';
|
|
|
|
import { ViewStatuteParagraph } from '../models/view-statute-paragraph';
|
|
|
|
import { StatuteParagraph } from '../../../shared/models/motions/statute-paragraph';
|
2018-10-26 11:19:05 +02:00
|
|
|
import { Identifiable } from '../../../shared/models/base/identifiable';
|
2018-11-02 08:34:33 +01:00
|
|
|
import { CollectionStringModelMapperService } from '../../../core/services/collectionStringModelMapper.service';
|
2018-10-12 11:05:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Repository Services for statute paragraphs
|
|
|
|
*
|
|
|
|
* Rather than manipulating models directly, the repository is meant to
|
|
|
|
* inform the {@link DataSendService} about changes which will send
|
|
|
|
* them to the Server.
|
|
|
|
*/
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class StatuteParagraphRepositoryService extends BaseRepository<ViewStatuteParagraph, StatuteParagraph> {
|
|
|
|
/**
|
|
|
|
* Creates a StatuteParagraphRepository
|
|
|
|
* Converts existing and incoming statute paragraphs to ViewStatuteParagraphs
|
|
|
|
* Handles CRUD using an observer to the DataStore
|
2018-11-09 13:44:39 +01:00
|
|
|
*
|
|
|
|
* @param DS The DataStore
|
|
|
|
* @param mapperService Maps collection strings to classes
|
|
|
|
* @param dataSend sending changed objects
|
2018-10-12 11:05:24 +02:00
|
|
|
*/
|
2018-11-02 08:34:33 +01:00
|
|
|
public constructor(
|
|
|
|
DS: DataStoreService,
|
|
|
|
mapperService: CollectionStringModelMapperService,
|
|
|
|
private dataSend: DataSendService
|
|
|
|
) {
|
|
|
|
super(DS, mapperService, StatuteParagraph);
|
2018-10-12 11:05:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected createViewModel(statuteParagraph: StatuteParagraph): ViewStatuteParagraph {
|
|
|
|
return new ViewStatuteParagraph(statuteParagraph);
|
|
|
|
}
|
|
|
|
|
2018-10-26 11:19:05 +02:00
|
|
|
public async create(statuteParagraph: StatuteParagraph): Promise<Identifiable> {
|
|
|
|
return await this.dataSend.createModel(statuteParagraph);
|
2018-10-12 11:05:24 +02:00
|
|
|
}
|
|
|
|
|
2018-10-26 11:19:05 +02:00
|
|
|
public async update(
|
2018-10-12 11:05:24 +02:00
|
|
|
statuteParagraph: Partial<StatuteParagraph>,
|
|
|
|
viewStatuteParagraph: ViewStatuteParagraph
|
2018-10-26 11:19:05 +02:00
|
|
|
): Promise<void> {
|
2018-10-12 11:05:24 +02:00
|
|
|
const updateParagraph = viewStatuteParagraph.statuteParagraph;
|
|
|
|
updateParagraph.patchValues(statuteParagraph);
|
2018-10-26 11:19:05 +02:00
|
|
|
await this.dataSend.updateModel(updateParagraph);
|
2018-10-12 11:05:24 +02:00
|
|
|
}
|
|
|
|
|
2018-10-26 11:19:05 +02:00
|
|
|
public async delete(viewStatuteParagraph: ViewStatuteParagraph): Promise<void> {
|
|
|
|
await this.dataSend.deleteModel(viewStatuteParagraph.statuteParagraph);
|
2018-10-12 11:05:24 +02:00
|
|
|
}
|
|
|
|
}
|