calculate logic on api side