async create(request) {
        const data = await request.getData();

        if (!data) request.response().status(400).send(`Missing request body!`);
        else if (!type.object(data)) request.response().status(400).send(`Request body must be a json object!`);
        else if (!type.string(data.sourceText)) request.response().status(400).send(`Missing parameter 'sourceText' in request body!`);
        else if (!type.string(data.specifier)) request.response().status(400).send(`Missing parameter 'specifier' in request body!`);
        else if (!type.string(data.dataSetIdentifier)) request.response().status(400).send(`Missing parameter 'dataSetIdentifier' in request body!`);
        else {
            const dataSet = await this.db.dataSet({
                identifier: data.dataSetIdentifier
            }).findOne();

            if (!dataSet) {
                return await request.response().status(400).send(`Dataset '${data.dataSetIdentifier}' does not exist!`);
            }

            await new this.db.sourceCode({
                sourceText: data.sourceText,
                specifier: data.specifier,
                dataSet,
            }).save();
        }
    }
/**
    * add source code to the db
    */
add source code to the db
add source code to the db
async create(request) {
        const data = await request.getData();
        if (!data) request.response().status(400).send(`Missing request body!`);
        else if (!type.object(data)) request.response().status(400).send(`Request body must be a json object!`);
        else if (!type.string(data.sourceText)) request.response().status(400).send(`Missing parameter 'sourceText' in request body!`);
        else if (!type.string(data.specifier)) request.response().status(400).send(`Missing parameter 'specifier' in request body!`);
        else if (!type.string(data.dataSetIdentifier)) request.response().status(400).send(`Missing parameter 'dataSetIdentifier' in request body!`);
        else {
            const dataSet = await this.db.dataSet({
                identifier: data.dataSetIdentifier
            }).findOne();
            if (!dataSet) {
                return await request.response().status(400).send(`Dataset '${data.dataSetIdentifier}' does not exist!`);
            }
            await new this.db.sourceCode({
                sourceText: data.sourceText,
                specifier: data.specifier,
                dataSet,
            }).save();
        }
    }
async create ( request ) { const data = await request . getData ( ) ; if ( ! data ) request . response ( ) . status ( 400 ) . send ( ` ` ) ; else if ( ! type . object ( data ) ) request . response ( ) . status ( 400 ) . send ( ` ` ) ; else if ( ! type . string ( data . sourceText ) ) request . response ( ) . status ( 400 ) . send ( ` ` ) ; else if ( ! type . string ( data . specifier ) ) request . response ( ) . status ( 400 ) . send ( ` ` ) ; else if ( ! type . string ( data . dataSetIdentifier ) ) request . response ( ) . status ( 400 ) . send ( ` ` ) ; else { const dataSet = await this . db . dataSet ( { identifier : data . dataSetIdentifier } ) . findOne ( ) ; if ( ! dataSet ) { return await request . response ( ) . status ( 400 ) . send ( ` ${ data . dataSetIdentifier } ` ) ; } await new this . db . sourceCode ( { sourceText : data . sourceText , specifier : data . specifier , dataSet , } ) . save ( ) ; } }
add source code to the db
add source code to the db