Autoincrement serial number for wix custom form submission

My current code
collection name : Form Details
serialID name in collection : myserial

///top line:
import wixData from ‘wix-data’ ;
///

export async function FormDetails_beforeInsert ( item , context ) => {
let prevNumber = 0 , prevSerialId = ‘IMZSR00000’ ;
if (! item . serialId ){
const prevItemQuery = await wixData . query ( ‘FormDetails’ ), isNotempty ( ‘serialId’ ). limit ( 1 ). descending ( ‘serialId’ ). distinct ( ‘serialId’ );
const items = prevItemQuery . items ;
if ( items . length ){
prevSerialId = items [ 0 ];
}
} else {
prevSerialId = item . serailId ;
}
const nextNumber = Number ( prevSerialId . replace ( ‘IMZSR’ , ‘’ )) + 1 ; //this one will remove the ‘ABC’ and process the number itself and will add plus one;
item . serailId = ‘IMZSR’ + nextNum . toString (). padStart ( 5 , ‘0’ );
return item ;
})
. catch ( err => err . errorCode === ‘WDE0123’ ? CollctionName_beforeInsert ( item , context ) : Promise . reject ( err ));
}
//TODO: write your code here…
}