Skip to content

Commit

Permalink
s(eslint): update eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
Gijsdeman committed Feb 25, 2025
1 parent 166142c commit 2c2b30b
Show file tree
Hide file tree
Showing 30 changed files with 288 additions and 273 deletions.
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export default [
{ languageOptions: { parserOptions: { project: './tsconfig.eslint.json' } } },
...typescript,
{ rules: { 'import/no-named-as-default-member': 'off' } },
prettier
prettier,
];
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"format": "prettier --check .",
"format-fix": "prettier --write ."
"format:fix": "prettier --write ."
},
"author": "The 39th board of Study Association GEWIS",
"dependencies": {
Expand Down
18 changes: 13 additions & 5 deletions src/auth/LDAPStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ import UserService from '../services/UserService';
import { Roles } from '../entity/enums/Roles';
import AppDataSource from '../database';

export interface LDAPUser {
memberOfFlattened: string[];
mail: string;
givenName: string;
sn: string;
sAMAccountName: string;
}

const isDefined = (i: string | undefined) => i !== undefined && i !== '';

export const ldapEnabled = () =>
Expand All @@ -28,7 +36,7 @@ export const LDAPStrategy = new Strategy({
},
});

const checkAllowedRoles = async (ldapUser: any): Promise<Roles[]> => {
const checkAllowedRoles = async (ldapUser: LDAPUser): Promise<Roles[]> => {
const roles = await AppDataSource.getRepository(Role).find();
const userRoles: Roles[] = [];
roles.forEach((role) => {
Expand All @@ -39,7 +47,7 @@ const checkAllowedRoles = async (ldapUser: any): Promise<Roles[]> => {
return userRoles;
};

export const updateUserInformation = async (user: User, ldapUser: any): Promise<User> => {
export const updateUserInformation = async (user: User, ldapUser: LDAPUser): Promise<User> => {
const userRoles = await checkAllowedRoles(ldapUser);
await new UserService().assignRoles(user, userRoles);

Expand All @@ -54,7 +62,7 @@ export const updateUserInformation = async (user: User, ldapUser: any): Promise<
};

export const ldapLogin = (req: express.Request, res: express.Response, next: express.NextFunction) => {
passport.authenticate('ldapauth', async (err: any, ldapUser: any, info: any) => {
passport.authenticate('ldapauth', async (err: Error, ldapUser: LDAPUser, info: any) => {

Check failure on line 65 in src/auth/LDAPStrategy.ts

View workflow job for this annotation

GitHub Actions / build-and-lint / yarn-steps

Unsafe call of a(n) `any` typed value

Check failure on line 65 in src/auth/LDAPStrategy.ts

View workflow job for this annotation

GitHub Actions / build-and-lint / yarn-steps

Unexpected any. Specify a different type
if (err) {
return next(err);
}
Expand Down Expand Up @@ -84,13 +92,13 @@ export const ldapLogin = (req: express.Request, res: express.Response, next: exp
lastName: ldapUser.sn,
email: ldapUser.mail,
function: '',
} as any as User;
} as User;
user = await userRepo.save(user);

identity = {
id: user.id,
username: ldapUser.sAMAccountName,
} as any as IdentityLDAP;
} as IdentityLDAP;
identity = await identityRepo.save(identity);
identity = await identityRepo.findOne({
where: { id: identity.id },
Expand Down
4 changes: 2 additions & 2 deletions src/dbvalidator/GEWISrecipient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ export async function replaceGEWISRecipient() {
'\\GEWISRecipient\\xspace',
);

p.save();
p.save().catch((e) => console.error(e));
});

console.log(
console.warn(
`The following products had one or multiple instances of {instelling} replaced (${count}): ${logResult.substr(0, logResult.length - 2)}`,
);
}
72 changes: 39 additions & 33 deletions src/dbvalidator/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,25 @@ export async function allContractsAreCreated() {
contracts.forEach((c) => {
const createdStatus = c.activities.find((a) => a.subType === ContractStatus.CREATED);
if (createdStatus === undefined) {
activityRepo.save({
createdAt: new Date(c.createdAt.getDate() - 1),
updatedAt: new Date(),
createdById: c.createdById,
contractId: c.id,
type: ActivityType.STATUS,
subType: ContractStatus.CREATED,
descriptionEnglish: '',
descriptionDutch: '',
} as ContractActivity);
activityRepo
.save({
createdAt: new Date(c.createdAt.getDate() - 1),
updatedAt: new Date(),
createdById: c.createdById,
contractId: c.id,
type: ActivityType.STATUS,
subType: ContractStatus.CREATED,
descriptionEnglish: '',
descriptionDutch: '',
} as ContractActivity)
.catch((e) => console.error(e));

logResult += `C${c.id}, `;
count++;
}
});

console.log(
console.warn(
`The following contracts did not have a 'CREATED' status (${count}): ${logResult.substr(0, logResult.length - 2)}`,
);
}
Expand All @@ -61,16 +63,18 @@ export async function allProductsAreCancelledIfContractIsCancelled() {
const index = p.activities.find((a) => a.subType === ProductInstanceStatus.CANCELLED);

if (index === undefined) {
productInstanceActivityRepo.save({
createdAt: cancelledActivity.createdAt,
updatedAt: new Date(),
productInstanceId: p.id,
createdById: c.createdById,
type: ActivityType.STATUS,
subType: ProductInstanceStatus.CANCELLED,
descriptionEnglish: '',
descriptionDutch: '',
} as ProductInstanceActivity);
productInstanceActivityRepo
.save({
createdAt: cancelledActivity.createdAt,
updatedAt: new Date(),
productInstanceId: p.id,
createdById: c.createdById,
type: ActivityType.STATUS,
subType: ProductInstanceStatus.CANCELLED,
descriptionEnglish: '',
descriptionDutch: '',
} as ProductInstanceActivity)
.catch((e) => console.error(e));

logResult += `C${c.id} (P${p.id}), `;
count++;
Expand All @@ -79,7 +83,7 @@ export async function allProductsAreCancelledIfContractIsCancelled() {
}
});

console.log(
console.warn(
`The following cancelled contracts had non-cancelled products (${count}): ${logResult.substr(0, logResult.length - 2)}`,
);
}
Expand All @@ -105,16 +109,18 @@ export async function allProductsAreDeliveredIfContractIsFinished() {
);

if (index === undefined) {
productInstanceActivityRepo.save({
createdAt: finishedActivity.createdAt,
updatedAt: new Date(),
productInstanceId: p.id,
createdById: c.createdById,
type: ActivityType.STATUS,
subType: ProductInstanceStatus.DELIVERED,
descriptionEnglish: '',
descriptionDutch: '',
} as ProductInstanceActivity);
productInstanceActivityRepo
.save({
createdAt: finishedActivity.createdAt,
updatedAt: new Date(),
productInstanceId: p.id,
createdById: c.createdById,
type: ActivityType.STATUS,
subType: ProductInstanceStatus.DELIVERED,
descriptionEnglish: '',
descriptionDutch: '',
} as ProductInstanceActivity)
.catch((e) => console.error(e));

logResult += `C${c.id} (P${p.id}), `;
count++;
Expand All @@ -123,7 +129,7 @@ export async function allProductsAreDeliveredIfContractIsFinished() {
}
});

console.log(
console.warn(
`The following contracts were finished, but did not have delivered/cancelled products (${count}): ${logResult.substr(0, logResult.length - 2)}`,
);
}
24 changes: 13 additions & 11 deletions src/dbvalidator/invoices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,25 @@ export async function allInvoicesAreCreated() {
invoices.forEach((i) => {
const createdStatus = i.activities.find((a) => a.subType === InvoiceStatus.CREATED);
if (createdStatus === undefined) {
activityRepo.save({
createdAt: new Date(i.createdAt.getDate() - 1),
updatedAt: new Date(),
createdById: i.createdById,
invoiceId: i.id,
type: ActivityType.STATUS,
subType: InvoiceStatus.CREATED,
descriptionEnglish: '',
descriptionDutch: '',
} as InvoiceActivity);
activityRepo
.save({
createdAt: new Date(i.createdAt.getDate() - 1),
updatedAt: new Date(),
createdById: i.createdById,
invoiceId: i.id,
type: ActivityType.STATUS,
subType: InvoiceStatus.CREATED,
descriptionEnglish: '',
descriptionDutch: '',
} as InvoiceActivity)
.catch((e) => console.error(e));

logResult += `F${i.id}, `;
count++;
}
});

console.log(
console.warn(
`The following invoices did not have a 'CREATED' status (${count}): ${logResult.substr(0, logResult.length - 2)}`,
);
}
24 changes: 13 additions & 11 deletions src/dbvalidator/productInstances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,25 @@ export async function allProductInstancesWereNotDelivered() {
productInstances.forEach((p) => {
const notDeliveredStatus = p.activities.find((a) => a.subType === ProductInstanceStatus.NOTDELIVERED);
if (notDeliveredStatus === undefined) {
activityRepo.save({
createdAt: new Date(p.createdAt.getDate() - 1),
updatedAt: new Date(),
productInstanceId: p.id,
createdById: p.contract.createdById,
type: ActivityType.STATUS,
subType: ProductInstanceStatus.NOTDELIVERED,
descriptionEnglish: '',
descriptionDutch: '',
} as ProductInstanceActivity);
activityRepo
.save({
createdAt: new Date(p.createdAt.getDate() - 1),
updatedAt: new Date(),
productInstanceId: p.id,
createdById: p.contract.createdById,
type: ActivityType.STATUS,
subType: ProductInstanceStatus.NOTDELIVERED,
descriptionEnglish: '',
descriptionDutch: '',
} as ProductInstanceActivity)
.catch((e) => console.error(e));

logResult += `C${p.contractId} (P${p.id}), `;
count++;
}
});

console.log(
console.warn(
`The following contracts had products that do not have a 'NOTDELIVERED' status (${count}): ${logResult.substr(0, logResult.length - 2)}`,
);
}
28 changes: 15 additions & 13 deletions src/dbvalidator/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ import { replaceGEWISRecipient } from './GEWISrecipient';

dotenv.config({ path: '.env' });

AppDataSource.initialize().then(async () => {
const t1 = new Date();
console.log('Start database validation...');
await Promise.all([
allContractsAreCreated(),
allInvoicesAreCreated(),
allProductInstancesWereNotDelivered(),
allProductsAreCancelledIfContractIsCancelled(),
allProductsAreDeliveredIfContractIsFinished(),
replaceGEWISRecipient(),
]);
console.log(`Database validated in ${new Date().getTime() - t1.getTime()}ms`);
});
AppDataSource.initialize()
.then(async () => {
const t1 = new Date();
console.warn('Start database validation...');
await Promise.all([
allContractsAreCreated(),
allInvoicesAreCreated(),
allProductInstancesWereNotDelivered(),
allProductsAreCancelledIfContractIsCancelled(),
allProductsAreDeliveredIfContractIsFinished(),
replaceGEWISRecipient(),
]);
console.warn(`Database validated in ${new Date().getTime() - t1.getTime()}ms`);
})
.catch((e) => console.error(e));
Loading

0 comments on commit 2c2b30b

Please sign in to comment.