Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (error) {
console.error('import failed...')
console.error(error)
}
console.log('inserted %d rows', rowCount)
})
// setup your columns - always indicate whether the column is nullable
// TODO add all fields that are being imported to this list
bulkLoad.addColumn('school_id', TYPES.Int, {nullable: false})
bulkLoad.addColumn('upn', TYPES.Char, {length: 13, nullable: false})
bulkLoad.addColumn('lastName', TYPES.NVarChar, {length: 'max', nullable: false})
bulkLoad.addColumn('foreName', TYPES.NVarChar, {length: 'max', nullable: false})
bulkLoad.addColumn('middleNames', TYPES.NVarChar, {length: 'max', nullable: true})
bulkLoad.addColumn('gender', TYPES.Char, {length: 1, nullable: false})
bulkLoad.addColumn('dateOfBirth', TYPES.DateTimeOffset, {nullable: false})
const schools = schoolLookupDisabled ? schoolData : await schoolLookup(csvPayload)
for (let index = 0; index < csvPayload.length; index++) {
const csvRow = csvPayload[index]
const dfeNumber = `${csvRow[0]}${csvRow[1]}`
const school = schools.find(s => s.dfeNumber === parseInt(dfeNumber))
const schoolId = school && school.id
if (!schoolId) {
console.error(`School id not found for DfeNumber ${dfeNumber}`)
process.exit(1)
}
bulkLoad.addRow({
school_id: schoolId,
upn: csvRow[2],
lastName: csvRow[3],
foreName: csvRow[4],
for (let i = 0; i < numSchools; i++) {
let school = schools[i]
let totalPupils = pupilsPerSchool
if (i < pupilsRemainder) {
totalPupils += 1
}
params = [
{
name: 'schoolId',
value: school.id,
type: TYPES.Int
},
{
name: 'dateOfBirth',
value: randomDob(),
type: TYPES.DateTimeOffset
},
{
name: 'pinExpiresAt',
value: pinExpiryDate,
type: TYPES.DateTimeOffset
}
]
const sql = `
DECLARE @cnt INT = 1;
DECLARE @baseUpn INT = 80120000 + @schoolId;
DECLARE @tvp AS ${sqlService.adminSchema}.CheckTableType;
DECLARE @existingPupils INT = 0;
BEGIN TRAN
UPDATE ${sqlService.adminSchema}.[school]
}
params = [
{
name: 'schoolId',
value: school.id,
type: TYPES.Int
},
{
name: 'dateOfBirth',
value: randomDob(),
type: TYPES.DateTimeOffset
},
{
name: 'pinExpiresAt',
value: pinExpiryDate,
type: TYPES.DateTimeOffset
}
]
const sql = `
DECLARE @cnt INT = 1;
DECLARE @baseUpn INT = 80120000 + @schoolId;
DECLARE @tvp AS ${sqlService.adminSchema}.CheckTableType;
DECLARE @existingPupils INT = 0;
BEGIN TRAN
UPDATE ${sqlService.adminSchema}.[school]
SET pin = '${randomPass()}', pinExpiresAt = @pinExpiresAt
WHERE id = ${school.id} AND pin IS NULL;
WHILE @cnt <= ${totalPupils}
BEGIN