Demeter in his book "Fourier Restriction, Decoupling, and Applications" (P287) used the following estimate:

\begin{equation}
\sup_{0\leq n\leq q}\bigg|\sum_{m=0}^n e^{2\pi i\frac{a}{q}m^2}\bigg|\leq Cq^{\frac{1}{2}},
\end{equation} 
where $a,q\in \mathbb{N}_+$ satisfy $(a,q)=1$ and $2\nmid q$.

The case $n=q$ can be calculated directly to be $q^{\frac{1}{2}}$. For general $n$, the usual Weyl's method will lead to an extra term $\log n$. Could you please explain how to get this estimate?