'use strict';


exports.save = async function () {
    await this.bindDefault();
    this.body =  await this.mongo("Url",this.request.body).saveByKey();
	return
}
exports.save.__method__ = 'POST';

exports.get_item = async function(){
    await this.bindDefault();
    this.body =  await this.mongo("Url").findItemBytId(this.request.query._id);
	return
}
exports.get_item.__method__ = "GET"

exports.query_items = async function(){
    await this.bindDefault();
    this.body =  await this.mongo("Url").findProByProjectId(this.request.query._id);
	return
}
exports.query_items.__method__ = "GET"

exports.query = async function () {
    await this.bindDefault();
    this.body =  await this.mongo("Url").findByProjectId(this.request.query._id);
	return
}
exports.query.__method__ = 'GET';


exports.delete = async function(){
    await this.bindDefault();
    this.body = await this.mongo("Url").delete(this.request.query._id);
    return
}
exports.delete.__method__ = "GET";


exports.update = async function(){
    await this.bindDefault();
    this.body = await this.mongo("Url").updateById(this.request.body);
    return
}
exports.update.__method__ = "POST"

exports.find = async function(){
    await this.bindDefault();
    this.body = await this.mongo("Url").findByObj(this.request.query);
    return
}
exports.find.__method__ = "GET"

exports.find_url_templates_by_id = async function(){
    await this.bindDefault();
    this.body = await this.mongo("Url").findUrlTemplatesById(this.request.query);
    return
}
exports.find_url_templates_by_id.__method__ = "GET"

exports.sub_relace_env = async function(vappOpt){
    await this.bindDefault();
    await this.mongo("Url").release(this.request.query._id);
    let url = await this.mongo("Url").findUrlTemplatesByUrlId(this.request.query._id);
    console.log("the url ---------------------",url)
    try {
        
        vappOpt.bpModules.route_config.setUrlTemplate(url[0]);
        this.body = {code:"0000",data: url[0]}
    } catch (error) {
        this.body = {code:"0001",err:error}
    }
    // this.body = {code}
    return
}
exports.sub_relace_env.__method__ = "GET"

exports.get_relace_flg = async function(){
    await this.bindDefault();
    this.body = await this.mongo("Url").findUrlRelaceFlgById(this.request.query._id);
    return
}
exports.get_relace_flg.__method__ = "GET"
