-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
765 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
import bcrypt from 'bcryptjs'; | ||
import { Knex } from 'knex'; | ||
import { UserApi } from '../../../server/models/UserApi'; | ||
import userRepository, { | ||
usersTable, | ||
} from '../../../server/repositories/userRepository'; | ||
import { usersTable } from '../../../server/repositories/userRepository'; | ||
import { genUserApi } from '../../../server/test/testFixtures'; | ||
|
||
export const User1: UserApi = genUserApi(); | ||
export const User2: UserApi = genUserApi(); | ||
|
||
exports.seed = async function (knex: Knex) { | ||
const hash = await bcrypt.hash(User1.password, 10); | ||
const hash1 = await bcrypt.hash(User1.password, 10); | ||
const hash2 = await bcrypt.hash(User2.password, 10); | ||
await knex.table(usersTable).insert([ | ||
userRepository.formatUserApi({ | ||
{ | ||
...User1, | ||
password: hash, | ||
}), | ||
password: hash1, | ||
}, | ||
{ | ||
...User2, | ||
password: hash2, | ||
}, | ||
]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import sampleRepository from '../../../server/repositories/sampleRepository'; | ||
import { genSample } from '../../../server/test/testFixtures'; | ||
import { Sample } from '../../../shared/schema/Sample'; | ||
import { User1, User2 } from './001-users'; | ||
|
||
export const Sample1: Sample = genSample(User1.id); | ||
export const Sample2: Sample = genSample(User2.id); | ||
|
||
exports.seed = async function () { | ||
await sampleRepository.insert(Sample1); | ||
await sampleRepository.insert(Sample2); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,53 @@ | ||
import { SampleToCreate } from 'shared/schema/Sample'; | ||
import fp from 'lodash'; | ||
import { | ||
PartialSample, | ||
PartialSampleUpdate, | ||
SampleToCreate, | ||
} from 'shared/schema/Sample'; | ||
import { api } from 'src/services/api.service'; | ||
|
||
export const sampleApi = api.injectEndpoints({ | ||
endpoints: (builder) => ({ | ||
createSample: builder.mutation<void, SampleToCreate>({ | ||
createSample: builder.mutation<string, SampleToCreate>({ | ||
query: (draft) => ({ | ||
url: 'samples', | ||
method: 'POST', | ||
body: { ...draft }, | ||
}), | ||
transformResponse: (response: any) => response.id, | ||
}), | ||
getSample: builder.query<PartialSample, string>({ | ||
query: (sampleId) => `samples/${sampleId}`, | ||
transformResponse: (response: any) => | ||
PartialSample.parse(fp.omitBy(response, fp.isNil)), | ||
providesTags: (result, error, sampleId) => | ||
result ? [{ type: 'Sample', id: sampleId }] : [], | ||
}), | ||
findSamples: builder.query<PartialSample[], void>({ | ||
query: () => 'samples', | ||
transformResponse: (response: any[]) => | ||
response.map((_) => PartialSample.parse(fp.omitBy(_, fp.isNil))), | ||
providesTags: (result) => | ||
result ? result.map(({ id }) => ({ type: 'Sample', id })) : [], | ||
}), | ||
updateSample: builder.mutation< | ||
void, | ||
{ sampleId: string; sampleUpdate: PartialSampleUpdate } | ||
>({ | ||
query: ({ sampleId, sampleUpdate }) => ({ | ||
url: `samples/${sampleId}`, | ||
method: 'PUT', | ||
body: sampleUpdate, | ||
}), | ||
invalidatesTags: (result, error, { sampleId }) => | ||
result ? [{ type: 'Sample', id: sampleId }] : [], | ||
}), | ||
}), | ||
}); | ||
|
||
export const { useCreateSampleMutation } = sampleApi; | ||
export const { | ||
useCreateSampleMutation, | ||
useFindSamplesQuery, | ||
useGetSampleQuery, | ||
useUpdateSampleMutation, | ||
} = sampleApi; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.