<commit_before>import * as mongoose from 'mongoose';

import { IOrganization, Organization } from '../interfaces/organizations';
import { OrganizationsDB } from './schemas/organizations';

export class Organizations implements IOrganization {
    constructor() { }

    public save(organization: Organization): Promise<any> {
        let org = new OrganizationsDB();
        org.convertToSchema(organization);

        return new Promise<any>((resolve, reject) => {
            org.save((err) => {
                if (err) reject(err);

                resolve(1);
            });
        });
    }

    public delete(id: number): Promise<any> {
        return new Promise<any>((resolve, reject) => {
            OrganizationsDB.findByIdAndRemove(id, (err) => {
                if (err) reject(err);

                resolve();
            });
        });
    }

    public get(id: number): Promise<Organization> {
        return new Promise<Organization>((resolve, reject) => {
            OrganizationsDB.findById(id, (err, org) => {
                if (err) reject(err);

                resolve(org.convertFromSchema());
            });
        });
    }

    public getAll(): Promise<Organization[]> {
        return new Promise<Organization[]>((resolve, reject) => {
            OrganizationsDB.find({}, (err, orgModels) => {
                if (err) reject(err);

                let orgs = orgModels.map<Organization>((org) => { return org.convertFromSchema(); });
                resolve(orgs);
            });
        });
    }
}
<commit_msg>corrected 'save()' to save new items and update old (#38)<commit_after>import * as mongoose from 'mongoose';

import { IOrganization, Organization } from '../interfaces/organizations';
import { OrganizationsDB } from './schemas/organizations';

export class Organizations implements IOrganization {
    constructor() { }

    public save(organization: Organization): Promise<any> {
        let org = new OrganizationsDB();
        org.convertToSchema(organization);

        return new Promise<any>((resolve, reject) => {
            if (!!org._id) {
            org.save((err) => {
                if (err) reject(err);

                resolve(1);
            });
            } else {
                OrganizationsDB.findByIdAndUpdate(org._id, org, (err => {
                    if (err) reject(err);

                    resolve(1);
                }));                
            }
        });
    }

    public delete(id: number): Promise<any> {
        return new Promise<any>((resolve, reject) => {
            OrganizationsDB.findByIdAndRemove(id, (err) => {
                if (err) reject(err);

                resolve();
            });
        });
    }

    public get(id: number): Promise<Organization> {
        return new Promise<Organization>((resolve, reject) => {
            OrganizationsDB.findById(id, (err, org) => {
                if (err) reject(err);

                resolve(org.convertFromSchema());
            });
        });
    }

    public getAll(): Promise<Organization[]> {
        return new Promise<Organization[]>((resolve, reject) => {
            OrganizationsDB.find({}, (err, orgModels) => {
                if (err) reject(err);

                let orgs = orgModels.map<Organization>((org) => { return org.convertFromSchema(); });
                resolve(orgs);
            });
        });
    }
}

{'fraction_non_alphanumeric': 0.14096527369040612, 'fraction_numerical': 0.0014714537963507945, 'mean_word_length': 1.8732037193575655, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 40, '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': '957427', 'n_tokens_mistral': 929, 'n_tokens_neox': 881, 'n_words': 191}