<commit_before>const logger = require('../../logger');
const { Kommission } = require('../models/kommission');
const { createUserError } = require('../../utils');

/**
 * Return all kommissions of the app.
 *
 * @returns {Promise<Array>} Kommissions
 */
async function getAllKommissions() {

    logger.verbose('Kommission service: get all kommissions');
    return await Kommission.findAll();
}


/**
 * Create a kommission.
 *
 * @param newKommission {Kommission} partial kommission
 * @return {Promise<Kommission|Errors.ValidationError>} The created kommission with its id
 */
async function createKommission(newKommission) {
    
    logger.verbose('Kommission service: creating a new kommission named %s %s', newKommission.firstName, newKommission.lastName);
    return await newKommission.save();
}
    

/**
     * Get a kommission by its id.
     *
     * @param kommissionId {number} Kommission id
     * @return {Promise<Kommission>} The wanted kommission.
     */
async function getKommissionById(kommissionId) {
    
    logger.verbose('Kommission service: get kommission by id %d', kommissionId);
    
    const kommission = await Kommission.findById(kommissionId);
    
    if (!kommission) throw createUserError('UnknownKommission', 'This kommission does not exist');
    
    return kommission;
}
    
    
/**
     * Update an kommission.
     * This will copy only the allowed changes from the `updatedKommission`
     * into the current kommission.
     * This means, with this function, you can not change everything like
     * the `createdAt` field or others.
     *
     * @param kommissionId {number} kommission id
     * @param updatedKommission {Kommission} Updated kommission, constructed from the request.
     * @return {Promise<Kommission>} The updated kommission
     */
async function updateKommission(kommissionId, updatedKommission) {
    
    const currentKommission = await Kommission.findById(kommissionId);
    
    if (!currentKommission) throw createUserError('UnknownKommission', 'This kommission does not exist');
    
    logger.verbose('Kommission service: updating kommission named %s %s', currentKommission.firstName, currentKommission.lastName);
    
    return await currentKommission.update({
        name: updatedKommission.name,
        description: updatedKommission.description,
            
    });
}
    
/**
     * Delete an kommission.
     *
     * @param kommissionId {number} kommission id.
     * @return {Promise<Kommission>} The deleted kommission
     */
async function deleteKommission(kommissionId) {
    
    logger.verbose('Kommission service: deleting kommission with id %d', kommissionId);
    
    const kommission = await Kommission.findById(kommissionId);
    
    if (!kommission) throw createUserError('UnknownKommission', 'This kommission does not exist');
    
    await kommission.destroy();
    
    return kommission;
}
    

module.exports = {
    getAllKommissions,
    createKommission,
    updateKommission,
    getKommissionById,
    deleteKommission
};
<commit_msg>first changes<commit_after>const logger = require('../../logger');
const { Kommission } = require('../models/kommission');
const { createUserError } = require('../../utils');

/**
 * Return all kommissions of the app.
 *
 * @returns {Promise<Array>} Kommissions
 */
async function getAllKommissions() {

    logger.verbose('Kommission service: get all kommissions');
    return await Kommission.findAll();
}


/**
 * Create a kommission.
 *
 * @param newKommission {Kommission} partial kommission
 * @return {Promise<Kommission|Errors.ValidationError>} The created kommission with its id
 */
async function createKommission(newKommission) {
    
    logger.verbose('Kommission service: creating a new kommission named %s %s', newKommission.firstName, newKommission.lastName);
    return await newKommission.save();
}
    

/**
     * Get a kommission by its id.
     *
     * @param kommissionId {number} Kommission id
     * @return {Promise<Kommission>} The wanted kommission.
     */
async function getKommissionById(kommissionId) {
    
    logger.verbose('Kommission service: get kommission by id %d', kommissionId);
    
    const kommission = await Kommission.findById(kommissionId);
    
    if (!kommission) throw createUserError('UnknownKommission', 'This kommission does not exist');
    
    return kommission.getBarmans();
}
    
    
/**
     * Update an kommission.
     * This will copy only the allowed changes from the `updatedKommission`
     * into the current kommission.
     * This means, with this function, you can not change everything like
     * the `createdAt` field or others.
     *
     * @param kommissionId {number} kommission id
     * @param updatedKommission {Kommission} Updated kommission, constructed from the request.
     * @return {Promise<Kommission>} The updated kommission
     */
async function updateKommission(kommissionId, updatedKommission) {
    
    const currentKommission = await Kommission.findById(kommissionId);
    
    if (!currentKommission) throw createUserError('UnknownKommission', 'This kommission does not exist');
    
    logger.verbose('Kommission service: updating kommission named %s %s', currentKommission.firstName, currentKommission.lastName);
    
    return await currentKommission.update({
        name: updatedKommission.name,
        description: updatedKommission.description,
            
    });
}
    
/**
     * Delete an kommission.
     *
     * @param kommissionId {number} kommission id.
     * @return {Promise<Kommission>} The deleted kommission
     */
async function deleteKommission(kommissionId) {
    
    logger.verbose('Kommission service: deleting kommission with id %d', kommissionId);
    
    const kommission = await Kommission.findById(kommissionId);
    
    if (!kommission) throw createUserError('UnknownKommission', 'This kommission does not exist');
    
    await kommission.destroy();
    
    return kommission;
}
    

module.exports = {
    getAllKommissions,
    createKommission,
    updateKommission,
    getKommissionById,
    deleteKommission
};

{'fraction_non_alphanumeric': 0.0999182338511856, 'fraction_numerical': 0.0, 'mean_word_length': 3.4805860805860807, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '2389046', 'n_tokens_mistral': 1739, 'n_tokens_neox': 1716, 'n_words': 473}