Companies table (#79)
* Add columns to companies: * account_owner_id * employees * address Add foreign key constraint companies_account_owner_id_fkey to auth.users.id * Add select permissions to: * account_owner_id * employees * address Add relationship between companies and auth.users. * Update Companies interface to include: * account_owner_id * employees * address Opportunity is expected to be replace by actual opportunity in a separate PR. * Add GetCompanies query * Add initial companies table * Update test to use mock apollo provider * Update to match changed company column names * Add company interface mapping tests * Test entire object * Add test for companies being rendered in table. * Add test for sorting reduce. * Fix prettier errors
This commit is contained in:
@ -1,5 +1,59 @@
|
||||
import { User } from './user.interface';
|
||||
|
||||
export interface Opportunity {
|
||||
name: string;
|
||||
icon: string;
|
||||
}
|
||||
|
||||
export interface Company {
|
||||
id: string;
|
||||
name: string;
|
||||
domain_name: string;
|
||||
employees: number;
|
||||
address: string;
|
||||
opportunities: Opportunity[];
|
||||
accountOwner: User;
|
||||
creationDate: Date;
|
||||
}
|
||||
|
||||
export type GraphqlQueryAccountOwner = {
|
||||
id: string;
|
||||
email: string;
|
||||
displayName: string;
|
||||
};
|
||||
|
||||
export type GraphqlQueryCompany = {
|
||||
id: string;
|
||||
name: string;
|
||||
domain_name: string;
|
||||
account_owner: GraphqlQueryAccountOwner;
|
||||
employees: number;
|
||||
address: string;
|
||||
created_at: string;
|
||||
};
|
||||
|
||||
export const mapCompany = (company: GraphqlQueryCompany): Company => ({
|
||||
...company,
|
||||
name: company.name,
|
||||
domain_name: company.domain_name,
|
||||
accountOwner: {
|
||||
id: company.account_owner.id,
|
||||
email: company.account_owner.email,
|
||||
first_name: company.account_owner.displayName.split(' ').shift() || '',
|
||||
last_name: company.account_owner.displayName.split(' ').slice(1).join(' '),
|
||||
},
|
||||
creationDate: new Date(company.created_at),
|
||||
opportunities: [{ name: 'Sales Pipeline', icon: '' }],
|
||||
});
|
||||
|
||||
export const mapGqlCompany = (company: Company): GraphqlQueryCompany => ({
|
||||
...company,
|
||||
name: company.name,
|
||||
domain_name: company.domain_name,
|
||||
created_at: company.creationDate.toUTCString(),
|
||||
account_owner: {
|
||||
id: company.accountOwner.id,
|
||||
email: company.accountOwner.email,
|
||||
displayName: `${company.accountOwner.first_name} ${company.accountOwner.last_name}`,
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user