<commit_before>﻿module Kitos.Services.DataProcessing {
    export interface IDataProcessingAgreementService {
        create(organizationId: number, name: string): angular.IPromise<IDataProcessingAgreementCreatedResult>;
        delete(dataProcessingAgreementId: number): angular.IPromise<IDataProcessingAgreementDeletedResult>;
        rename(dataProcessingAgreementId: number, name: string): angular.IPromise<IDataProcessingAgreementPatchResult>;
    }

    export interface IDataProcessingAgreementCreatedResult {
        createdObjectId : number;
    }


    export interface IDataProcessingAgreementDeletedResult {
        deleted: boolean;
        deletedObjectId: number;
        error: string;
    }

    export interface IDataProcessingAgreementPatchResult {
        modified: boolean;
        valueModified: string;
        error: string;
    }

    export class DataProcessingAgreementService implements IDataProcessingAgreementService {

        private handleServerError(error) {
            console.log("Request failed with:", error);
            let errorCategory: Models.Api.ApiResponseErrorCategory;
            switch (error.status) {
            case 400:
                errorCategory = Models.Api.ApiResponseErrorCategory.BadInput;
                break;
            case 409:
                errorCategory = Models.Api.ApiResponseErrorCategory.Conflict;
                break;
            case 500:
                errorCategory = Models.Api.ApiResponseErrorCategory.ServerError;
                break;
            default:
                errorCategory = Models.Api.ApiResponseErrorCategory.UnknownError;
            }
            throw errorCategory;
        }

        create(organizationId: number, name: string): angular.IPromise<IDataProcessingAgreementCreatedResult> {


        public rename(dataProcessingAgreementId: number, name: string): angular.IPromise<IDataProcessingAgreementPatchResult> { ;

            const payload  = {
                Value: name
            };

            return this
                .$http
                .patch<IApiWrapper<any>>(this.getUriWithIdAndSuffix(dataProcessingAgreementId.toString(), "name"), payload).then(
                    response => {
                    return <IDataProcessingAgreementPatchResult>{
                        modified: true,
                        valueModified: name,
                        error: ""
                    };
                },
                error => {
                    return <IDataProcessingAgreementPatchResult>{
                        modified: false,
                        valueModified: name,
                        error: error.data.msg
                };
                }
            );
        }

        public delete(dataProcessingAgreementId: number): angular.IPromise<IDataProcessingAgreementDeletedResult> {

            return this
                .$http
                .delete<IApiWrapper<any>>(this.getUri(dataProcessingAgreementId.toString()))
                .then(
                    response => {
                        return <IDataProcessingAgreementDeletedResult>{
                            deleted: true,
                            deletedObjectId: response.data.response.id,
                            error: "TODO"
                        };
                    },
                    error => {
                        return <IDataProcessingAgreementDeletedResult>{
                            deleted: false,
                            error: "TODO"
                        };
                    }
                );
<commit_msg>Clean up after merge<commit_after>﻿module Kitos.Services.DataProcessing {
    export interface IDataProcessingAgreementService {
        create(organizationId: number, name: string): angular.IPromise<IDataProcessingAgreementCreatedResult>;
        delete(dataProcessingAgreementId: number): angular.IPromise<IDataProcessingAgreementDeletedResult>;
        rename(dataProcessingAgreementId: number, name: string): angular.IPromise<IDataProcessingAgreementPatchResult>;
    }

    export interface IDataProcessingAgreementCreatedResult {
        createdObjectId : number;
    }


    export interface IDataProcessingAgreementDeletedResult {
        deleted: boolean;
        deletedObjectId: number;
        error: string;
    }

    export interface IDataProcessingAgreementPatchResult {
        modified: boolean;
        valueModified: string;
        error: string;
    }

    export class DataProcessingAgreementService implements IDataProcessingAgreementService {

        private handleServerError(error) {
            console.log("Request failed with:", error);
            let errorCategory: Models.Api.ApiResponseErrorCategory;
            switch (error.status) {
            case 400:
                errorCategory = Models.Api.ApiResponseErrorCategory.BadInput;
                break;
            case 409:
                errorCategory = Models.Api.ApiResponseErrorCategory.Conflict;
                break;
            case 500:
                errorCategory = Models.Api.ApiResponseErrorCategory.ServerError;
                break;
            default:
                errorCategory = Models.Api.ApiResponseErrorCategory.UnknownError;
            }
            throw errorCategory;
        }

        public rename(dataProcessingAgreementId: number, name: string): angular.IPromise<IDataProcessingAgreementPatchResult> { 

            const payload  = {
                Value: name
            };

            return this
                .$http
                .patch<API.Models.IApiWrapper<any>>(this.getUriWithIdAndSuffix(dataProcessingAgreementId.toString(), "name"), payload).then(
                    response => {
                    return <IDataProcessingAgreementPatchResult>{
                        modified: true,
                        valueModified: name,
                        error: ""
                    };
                },
                error => {
                    return <IDataProcessingAgreementPatchResult>{
                        modified: false,
                        valueModified: name,
                        error: error.data.msg
                };
                }
            );
        }

        public delete(dataProcessingAgreementId: number): angular.IPromise<IDataProcessingAgreementDeletedResult> {

            return this
                .$http
                .delete<API.Models.IApiWrapper<any>>(this.getUri(dataProcessingAgreementId.toString()))
                .then(
                    response => {
                        return <IDataProcessingAgreementDeletedResult>{
                            deleted: true,
                            deletedObjectId: response.data.response.id,
                            error: "TODO"
                        };
                    },
                    error => {
                        return <IDataProcessingAgreementDeletedResult>{
                            deleted: false,
                            error: "TODO"
                        };
                    }
                );

{'fraction_non_alphanumeric': 0.06969867642917488, 'fraction_numerical': 0.0025344973246972683, 'mean_word_length': 1.5467909645034061, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6986559', 'n_tokens_mistral': 1665, 'n_tokens_neox': 1516, 'n_words': 278}