Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#220] - Combine first_name and last_name into one name field #364

Open
wants to merge 16 commits into
base: main-a2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39,753 changes: 26,578 additions & 13,175 deletions backend/package-lock.json

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions backend/src/controllers/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export const createUser = async (
// Don't return auth_id in the response
res.status(httpStatus.CREATED).json({
_id: createdUser._id,
first_name: createdUser.first_name,
last_name: createdUser.last_name,
name: createdUser.name,
persons: createdUser.persons,
encounters: createdUser.encounters,
goals: createdUser.goals,
Expand Down Expand Up @@ -55,8 +54,7 @@ export const getUser = async (
// Don't return auth_id in the response
res.status(httpStatus.OK).json({
_id: user._id,
first_name: user.first_name,
last_name: user.last_name,
name: user.name,
persons: user.persons,
encounters: user.encounters,
goals: user.goals,
Expand Down
3 changes: 1 addition & 2 deletions backend/src/controllers/utils/controller-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ export default async function getPersonDetails(personId: any) {
let person = await personService.getPersonWithId(personId);
return {
_id: person?._id,
first_name: person?.first_name,
last_name: person?.last_name,
name: person?.name,
image: person?.image,
};
}
6 changes: 2 additions & 4 deletions backend/src/models/person.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import mongoose, { Schema, model } from 'mongoose';
import { Importance } from '../enums/importance';

export interface PersonModel {
first_name: string,
last_name: string,
name: string,
birthday: Date,
gender: string,
location: string,
Expand All @@ -24,8 +23,7 @@ export interface PersonModel {
}

const schema = new Schema<PersonModel>({
first_name: { type: String, required: true },
last_name: { type: String, required: false },
name: { type: String, required: true },
birthday: { type: Date, required: false },
gender: { type: String, required: false },
location: { type: String, required: false },
Expand Down
6 changes: 2 additions & 4 deletions backend/src/models/user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import mongoose, { Schema, model } from 'mongoose';

export interface UserModel {
auth_id: string,
first_name: string,
last_name: string,
name: string,
persons: mongoose.Types.ObjectId[]
encounters: mongoose.Types.ObjectId[]
goals: mongoose.Types.ObjectId[]
Expand All @@ -12,8 +11,7 @@ export interface UserModel {

const schema = new Schema<UserModel>({
auth_id: { type: String, required: true },
first_name: { type: String, required: true },
last_name: { type: String, required: true },
name: { type: String, required: true },
persons: { type: [mongoose.Types.ObjectId] },
encounters: { type: [mongoose.Types.ObjectId] },
goals: { type: [mongoose.Types.ObjectId] },
Expand Down
12 changes: 4 additions & 8 deletions backend/src/routes/__test__/company.route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ afterAll(async () => await databaseOperations.closeDatabase());

const user1Data = {
auth_id: null as any,
first_name: 'Bing',
last_name: 'Bong',
name: 'Bing Bong',
encounters: [] as any,
persons: [] as any,
goals: [] as any,
Expand All @@ -36,17 +35,15 @@ const user1Data = {

const user2Data: UserModel = {
auth_id: null as any,
first_name: 'Adam',
last_name: 'Weng',
name: 'Adam Weng',
encounters: [] as any,
goals: [] as any,
persons: [] as any,
companies: [] as any
}

const person1Data: PersonModel = {
first_name: 'Ping',
last_name: 'Pong',
name: 'Ping Pong',
interests: ['video games', 'hockey'],
labels: ['Devop'],
organisation: 'helloc',
Expand All @@ -64,8 +61,7 @@ const person1Data: PersonModel = {
};

const person2Data: PersonModel = {
first_name: 'Adam',
last_name: 'Bong',
name: 'Adam Bong',
interests: ['badminton', 'golf'],
labels: ['Devop'],
organisation: 'helloc',
Expand Down
12 changes: 4 additions & 8 deletions backend/src/routes/__test__/encounter.route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ afterAll(async () => await databaseOperations.closeDatabase());

const user1Data: UserModel = {
auth_id: null as any,
first_name: 'Bing',
last_name: 'Bong',
name: 'Bing Bong',
encounters: [] as any,
persons: [] as any,
goals: [] as any,
Expand All @@ -36,17 +35,15 @@ const user1Data: UserModel = {

const user2Data: UserModel = {
auth_id: null as any,
first_name: 'Adam',
last_name: 'Weng',
name: 'Adam Weng',
encounters: [] as any,
persons: [] as any,
goals: [] as any,
companies: [] as any
}

const person1Data: PersonModel = {
first_name: 'Ping',
last_name: 'Pong',
name: 'Ping Pong',
interests: ['video games', 'hockey'],
labels: ['Devop'],
organisation: 'helloc',
Expand All @@ -64,8 +61,7 @@ const person1Data: PersonModel = {
};

const person2Data: PersonModel = {
first_name: 'Adam',
last_name: 'Bong',
name: 'Adam Bong',
interests: ['badminton', 'golf'],
labels: ['Devop'],
organisation: 'helloc',
Expand Down
46 changes: 18 additions & 28 deletions backend/src/routes/__test__/person.route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,15 @@ afterAll(async () => await databaseOperations.closeDatabase());

const user1Data : UserModel = {
auth_id: null as any,
first_name: 'Bing',
last_name: 'Bong',
name: 'Bing Bong',
encounters: [] as any,
persons: [] as any,
goals: [] as any,
companies: [] as any
}

const person1Data: PersonModel = {
first_name: 'Ping',
last_name: 'Pong',
name: 'Ping Pong',
interests: ['video games', 'hockey'],
labels: ['Devop'],
organisation: 'helloc',
Expand All @@ -54,8 +52,7 @@ const person1Data: PersonModel = {
};

const person2Data: PersonModel = {
first_name: 'Adam',
last_name: 'Bong',
name: 'Adam Bong',
interests: ['badminton', 'golf'],
labels: ['Devop'],
organisation: 'helloc',
Expand All @@ -73,8 +70,7 @@ const person2Data: PersonModel = {
}

const person3Data: PersonModel = {
first_name: 'Billy',
last_name: 'John',
name: 'Billy John',
interests: ['surfing', 'cooking'],
labels: ['Devop'],
organisation: 'an organisation',
Expand All @@ -92,8 +88,7 @@ const person3Data: PersonModel = {
}

const person4Data: PersonModel = {
first_name: 'Kelvin',
last_name: 'Kong',
name: 'Kelvin Kong',
interests: ['Studying', 'Winning'],
labels: ['Devop'],
organisation: 'Winnie',
Expand All @@ -112,15 +107,14 @@ const person4Data: PersonModel = {

const userData: UserModel = {
auth_id: null as any,
first_name: 'Ping',
last_name: 'Pengy',
name: 'Ping Pengy',
encounters: [] as any,
persons: [] as any,
goals: [] as any,
companies: [] as any
}
const person5Data = {
last_name: 'John',
name: 'John',
interests: ['surfing', 'cooking'],
labels: ['Devop'],
organisation: 'an organisation',
Expand All @@ -138,8 +132,7 @@ const person5Data = {
}

const person6Data = {
first_name: 'Billy',
last_name: 'John',
name: 'Billy John',
interests: ['surfing', 'cooking'],
labels: ['Devop'],
organisation: 'an organisation',
Expand Down Expand Up @@ -175,8 +168,7 @@ const encounter2Data: EncounterModel = {
}

const person7Data = {
first_name: 'Yesterday',
last_name: 'Birthday',
name: 'Yesterday Birthday',
interests: ['surfing', 'cooking'],
labels: [],
organisation: 'an organisation',
Expand All @@ -191,8 +183,7 @@ const person7Data = {
}

const person8Data = {
first_name: 'Tomorrow',
last_name: 'Birthday',
name: 'Tomorrow Birthday',
interests: ['surfing', 'cooking'],
labels: ['Devop'],
organisation: 'an organisation',
Expand All @@ -207,8 +198,7 @@ const person8Data = {
}

const person9Data = {
first_name: 'NextMonth',
last_name: 'Birthday',
name: 'NextMonth Birthday',
interests: ['surfing', 'cooking'],
labels: ['Backend'],
organisation: 'an organisation',
Expand Down Expand Up @@ -314,7 +304,7 @@ describe('POST persons/', () => {
expect(user.persons).toEqual([createdPerson._id]);
});

it ('Cannot be created if a first name is not provided', async ()=> {
it ('Cannot be created if the name is not provided', async ()=> {
// Create a new user
await supertest(app).post('/api/users')
.set('Accept', 'application/json')
Expand Down Expand Up @@ -395,11 +385,11 @@ describe('GET persons/', () => {
});

it ('Correctly filters persons by the "term" query param', async () => {
person1Data.first_name = "Bing"
person1Data.name = "Bing Bong"
const person1ID = (await new Person(person1Data).save()).id;
person2Data.first_name = "Billy"
person2Data.name = "Billy John"
const person2ID = (await new Person(person2Data).save()).id;
person3Data.first_name = "John"
person3Data.name = "John"
const person3ID = (await new Person(person3Data).save()).id;

user1Data.persons = [person1ID, person2ID, person3ID];
Expand All @@ -414,8 +404,8 @@ describe('GET persons/', () => {
.expect(httpStatus.OK)

expect(retrievedPersons).toHaveLength(2);
expect(retrievedPersons[0].first_name).toBe("Bing");
expect(retrievedPersons[1].first_name).toBe("Billy");
expect(retrievedPersons[0].name).toBe("Bing Bong");
expect(retrievedPersons[1].name).toBe("Billy John");
});

it ('Returns all persons if the "term" query param is empty', async () => {
Expand All @@ -438,7 +428,7 @@ describe('GET persons/', () => {
});

it ('Does not return duplicates if all persons match the "term" query', async () => {
person1Data.first_name = "A test name";
person1Data.name = "A test name";
const person1ID = (await new Person(person1Data).save()).id;
const person2ID = (await new Person(person1Data).save()).id;
const person3ID = (await new Person(person1Data).save()).id;
Expand Down
Loading