Esempio n. 1
0
// FetchActiveAccounts fetches active acounts that are not processed yet
func (a *PresenceDaily) FetchActiveAccounts(query *request.Query) (*ActiveAccountResponse, error) {
	res := make([]accountRes, 0)
	err := bongo.B.DB.
		Table(a.BongoName()).
		Model(&PresenceDaily{}).
		Where("group_name = ? and is_processed = ?", query.GroupName, false).
		Order("created_at", true).
		Select("distinct account_id, created_at").
		Limit(query.Limit).
		Offset(query.Skip).
		Scan(&res).Error

	if err != nil {
		return nil, err
	}

	ids := make([]string, len(res))
	for i, id := range res {
		ids[i] = strconv.FormatInt(id.AccountId, 10)
	}

	acc, err := modelhelper.GetAccountBySocialApiIds(ids...)
	if err != nil {
		return nil, err
	}

	return &ActiveAccountResponse{
		Accounts:     acc,
		DeletedCount: len(ids) - len(acc),
	}, nil
}
Esempio n. 2
0
func TestGetAccountBySocialApiIds(t *testing.T) {
	db := modeltesthelper.NewMongoDB(t)
	defer db.Close()

	acc1 := createTestAccount(t)
	defer modelhelper.RemoveAccount(acc1.Id)

	acc2 := createTestAccount(t)
	defer modelhelper.RemoveAccount(acc2.Id)

	acc3 := createTestAccount(t)
	defer modelhelper.RemoveAccount(acc3.Id)

	accounts, err := modelhelper.GetAccountBySocialApiIds(acc1.SocialApiId, acc2.SocialApiId, acc3.SocialApiId)
	if err != nil {
		t.Error(err)
	}

	if len(accounts) != 3 {
		t.Errorf("accounts count should be 3, got: %d", len(accounts))
	}
}