-
Notifications
You must be signed in to change notification settings - Fork 0
/
payed_manager.coffee
62 lines (53 loc) · 2.93 KB
/
payed_manager.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Meteor.startup ->
Meteor.users.helpers
hasTicketsFor: (event) ->
return this.eventTickets?[event._id]?.length
define "EventticketManager", ["VoodoocontentModel"], (model) ->
self = {}
if Meteor.isServer
self.addTicketsToUser = (eventid, user, ticketno, paymentMethod= null) ->
mongoop = {}
console.log("adding tickets to user:", user, ticketno)
existingTickets = user.eventTickets["#{eventid}"]
existingTicketCount = existingTickets?.length
if (!existingTicketCount)
existingTicketCount = 0
console.log("already existing", existingTicketCount, ticketno)
#if (existingTicketCount >= ticketno)
# return
mongoop["#{eventid}"] = []
if (existingTicketCount > 0)
mongoop["#{eventid}"].push(existingTickets)
_.each([(existingTicketCount+1)..ticketno+existingTicketCount], (i) -> mongoop["#{eventid}"].push({nameOnList: (if i == 1 then user.profile?.name else null), price: null, ticketType: null, paymentMethod: paymentMethod}))
console.log("updating tickets ", user._id, mongoop["#{eventid}"])
Meteor.users.update(user._id, {$set: {eventTickets: mongoop}})
self.createUserWithTickets = (fullname, email, eventid, ticketno, paymentMethod=null) ->
console.log("createUserWithTickets2", fullname, paymentMethod)
user = Meteor.users.findOne({"emails.address": email})
unless user
Accounts.createUser({profile:{name: fullname}, email: email})
user = Meteor.users.findOne({"emails.address": email})
console.log("created user", fullname)
unless user.profile?.name?
Meteor.users.update({"emails.address": email}, {$set: {profile:{name: fullname}}})
self.addTicketsToUser(user,ticketno)
return Meteor.users.findOne({"emails.address": email})
return self
#dta = JSON.parse(Meteor.http.get("http://voodoohop.com/userpayed-json.php?eventid=831").content)
#eventid = model.getContentBySourceId("249217818582966")._id
#_.each(dta, (user) ->
# Meteor.call("createUserWithTickets",user.name, user.email, eventid,user.quantity,"paypal", (err,res) -> console.log(res))
#)
#namesAndEmails = _.map(_.filter(moippayments.split("\t"), (v,k) -> k % 6 == 0), (v,k) ->
# v.trim()
# nameandemail = v.trim().split(" ")
# email = nameandemail.pop().trim()
# name = nameandemail.join(" ").trim()
# return {name, email}
#)
#data = _.map(_.countBy(namesAndEmails, (i) -> i.name+","+i.email), (v,k) -> {name: k.split(",")[0], email: k.split(",")[1], count: v})
#_.each(data, (user) ->
# #console.log "createUserWithTickets",user.name, user.email, "2tFkF3j7CgN5K8EFy",user.count
# Meteor.call("createUserWithTickets",user.name, user.email, eventid, user.count, "MoIP", (err,res) -> console.log(res))
#)
require ["EventticketManager"], (ticketManager) ->