예제 #1
0
파일: customer.go 프로젝트: ninnemana/API
// Get all customers since a defined Id.
func CustomersSinceId(shopId bson.ObjectId, since_id bson.ObjectId, page, limit int, created_at_min, created_at_max, updated_at_min, updated_at_max *time.Time) ([]Customer, error) {
	custs := []Customer{}
	sess, err := mgo.DialWithInfo(database.MongoConnectionString())
	if err != nil {
		return custs, err
	}
	defer sess.Close()

	c := sess.DB("CurtCart").C("customer")
	qs := bson.M{
		"shop_id": shopId.String(),
		"_id": bson.M{
			"$gt": since_id.String(),
		},
		"$or": []bson.M{
			bson.M{"customer.addresses.deleted": false},
			bson.M{"customer.addresses.deleted": bson.M{
				"$exists": false,
			}},
		},
	}
	if created_at_min != nil || created_at_max != nil {
		createdQs := bson.M{}
		if created_at_min != nil {
			createdQs["&qt"] = created_at_min.String()
		}
		if created_at_max != nil {
			createdQs["&lt"] = created_at_max.String()
		}
		qs["created_at"] = createdQs
	}
	if updated_at_min != nil || updated_at_max != nil {
		updatedQs := bson.M{}
		if updated_at_min != nil {
			updatedQs["&qt"] = updated_at_min.String()
		}
		if updated_at_max != nil {
			updatedQs["&lt"] = updated_at_max.String()
		}
		qs["updated_at"] = updatedQs
	}

	if page == 1 {
		page = 0
	}
	err = c.Find(qs).Skip(page * limit).Limit(limit).All(&custs)
	if err != nil {
		return []Customer{}, err
	}

	for i, _ := range custs {
		custs[i].Password = ""
	}

	return custs, err
}
예제 #2
0
func FuncDelete(id bson.ObjectId) error {
	if err := RolePerDeleteByFunc(id.String()); err != nil {
		return err
	}
	return CloneDB().C(FuncColl).Remove(bson.M{"_id": id})
}