<commit_before>jraphical = require 'jraphical'
module.exports = class JKite extends jraphical.Module

  KodingError         = require '../error'
  {permit}            = require './group/permissionset'
  {signature}         = require 'bongo'
  {Relationship}      = jraphical

  @trait __dirname, '../traits/protected'

  @share()
  @set
    permissions           :
      'create kite'       : ['member']
      'list kites'        : ['member']
    schema                :
      name                : String
      description         : String
      createdAt           :
        type              : Date
        default           : -> new Date
    sharedEvents          :
      instance            : []
      static              : []
    sharedMethods         :
      static              :
        create            :
          (signature Object, Function)
        list              :
          (signature Object, Object, Function)
        one               :
          (signature Object, Function)
      instance            :
        modify            :
          (signature Object, Function)
        deleteKite        :
          (signature Function)
        fetchPlans        :
          (signature Function)
        createPlan        :
          (signature Object, Function)
        deletePlan        :
          (signature Object, Function)

    relationships       :
      plan              :
        targetType      : 'JPaymentPlan'
        as              : 'kitePlan'

  @create: permit 'create kite',
    success:(client, formData, callback)->
      kite = new JKite formData
      kite.save (err)->
        return  callback new KodingError "kite couldn't saved" if err
        account = client.connection.delegate
        account.addKite kite, (err, res)->
          return  callback new KodingError "kite couldn't added to account" if err
          callback null, kite

  @list: permit 'list kites',
    success: (client, selector, options, callback)->
      JKite.some selector, options, callback

  modify: permit 'edit kite',
    success: (client, formData, callback)->
      @update $set: {name: formData.name, description: formData.description} , callback

  deleteKite: permit 'delete kite',
    success: (client, callback)->
      account = client.connection.delegate
      Relationship.one {
        targeName   : "JKite"
        targetId    : @getId()
        sourceName  : "JAccount"
        sourceId    : account.getId()
        as          : "owner"
      }, (err, rel) =>
        return  callback new KodingError err if err
        @remove (err, res)->
          return  callback err, res
<commit_msg>KiteSubscription: add method to create plan<commit_after>jraphical = require 'jraphical'
module.exports = class JKite extends jraphical.Module

  KodingError         = require '../error'
  {permit}            = require './group/permissionset'
  {signature}         = require 'bongo'
  {Relationship}      = jraphical

  @trait __dirname, '../traits/protected'

  @share()
  @set
    permissions           :
      'create kite'       : ['member']
      'list kites'        : ['member']
    schema                :
      name                : String
      description         : String
      createdAt           :
        type              : Date
        default           : -> new Date
    sharedEvents          :
      instance            : []
      static              : []
    sharedMethods         :
      static              :
        create            :
          (signature Object, Function)
        list              :
          (signature Object, Object, Function)
        one               :
          (signature Object, Function)
      instance            :
        modify            :
          (signature Object, Function)
        deleteKite        :
          (signature Function)
        fetchPlans        :
          (signature Function)
        createPlan        :
          (signature Object, Function)
        deletePlan        :
          (signature Object, Function)

    relationships       :
      plan              :
        targetType      : 'JPaymentPlan'
        as              : 'kitePlan'

  @create: permit 'create kite',
    success:(client, formData, callback)->
      kite = new JKite formData
      kite.save (err)->
        return  callback new KodingError "kite couldn't saved" if err
        account = client.connection.delegate
        account.addKite kite, (err, res)->
          return  callback new KodingError "kite couldn't added to account" if err
          callback null, kite

  @list: permit 'list kites',
    success: (client, selector, options, callback)->
      JKite.some selector, options, callback

  modify: permit 'edit kite',
    success: (client, formData, callback)->
      @update $set: {name: formData.name, description: formData.description} , callback

  deleteKite: permit 'delete kite',
    success: (client, callback)->
      account = client.connection.delegate
      Relationship.one {
        targeName   : "JKite"
        targetId    : @getId()
        sourceName  : "JAccount"
        sourceId    : account.getId()
        as          : "owner"
      }, (err, rel) =>
        return  callback new KodingError err if err
        if rel
          @remove (err, res)->
            return  callback err, res

  createPlan: permit 'create kite',
    success: (client, formData, callback)->
      formData.tags = ["kite"]
      JPaymentPlan  = require './payment/plan'
      JPaymentPlan.create client.context.group, formData, (err, plan)=>
        return  callback err if err
        @addPlan plan, callback

{'fraction_non_alphanumeric': 0.09006433166547534, 'fraction_numerical': 0.0, 'mean_word_length': 1.542935029532031, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '3621798', 'n_tokens_mistral': 1449, 'n_tokens_neox': 1430, 'n_words': 415}