Skip to content

Commit

Permalink
Upgrade (#10)
Browse files Browse the repository at this point in the history
* Upgrade Ember-data
  • Loading branch information
AmauryD authored May 27, 2024
1 parent 542fc54 commit 31f31db
Show file tree
Hide file tree
Showing 40 changed files with 3,108 additions and 4,870 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/blueprints/*/files/

# compiled output
/declarations/
/dist/

# misc
Expand Down
56 changes: 56 additions & 0 deletions .husky/_/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/sh

if [ "$LEFTHOOK_VERBOSE" = "1" -o "$LEFTHOOK_VERBOSE" = "true" ]; then
set -x
fi

if [ "$LEFTHOOK" = "0" ]; then
exit 0
fi

call_lefthook()
{
dir="$(git rev-parse --show-toplevel)"
osArch=$(uname | tr '[:upper:]' '[:lower:]')
cpuArch=$(uname -m | sed 's/aarch64/arm64/')

if test -n "$LEFTHOOK_BIN"
then
"$LEFTHOOK_BIN" "$@"
elif lefthook -h >/dev/null 2>&1
then
lefthook "$@"
elif test -f "$dir/node_modules/lefthook/bin/index.js"
then
"$dir/node_modules/lefthook/bin/index.js" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook"
then
"$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook"
then
"$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@"

elif bundle exec lefthook -h >/dev/null 2>&1
then
bundle exec lefthook "$@"
elif yarn lefthook -h >/dev/null 2>&1
then
yarn lefthook "$@"
elif pnpm lefthook -h >/dev/null 2>&1
then
pnpm lefthook "$@"
elif swift package plugin lefthook >/dev/null 2>&1
then
swift package --disable-sandbox plugin lefthook "$@"
elif command -v mint >/dev/null 2>&1
then
mint run csjones/lefthook-plugin "$@"
elif command -v npx >/dev/null 2>&1
then
npx lefthook "$@"
else
echo "Can't find lefthook in PATH"
fi
}

call_lefthook run "pre-push" "$@"
56 changes: 56 additions & 0 deletions .husky/_/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/sh

if [ "$LEFTHOOK_VERBOSE" = "1" -o "$LEFTHOOK_VERBOSE" = "true" ]; then
set -x
fi

if [ "$LEFTHOOK" = "0" ]; then
exit 0
fi

call_lefthook()
{
dir="$(git rev-parse --show-toplevel)"
osArch=$(uname | tr '[:upper:]' '[:lower:]')
cpuArch=$(uname -m | sed 's/aarch64/arm64/')

if test -n "$LEFTHOOK_BIN"
then
"$LEFTHOOK_BIN" "$@"
elif lefthook -h >/dev/null 2>&1
then
lefthook "$@"
elif test -f "$dir/node_modules/lefthook/bin/index.js"
then
"$dir/node_modules/lefthook/bin/index.js" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook"
then
"$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook"
then
"$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@"

elif bundle exec lefthook -h >/dev/null 2>&1
then
bundle exec lefthook "$@"
elif yarn lefthook -h >/dev/null 2>&1
then
yarn lefthook "$@"
elif pnpm lefthook -h >/dev/null 2>&1
then
pnpm lefthook "$@"
elif swift package plugin lefthook >/dev/null 2>&1
then
swift package --disable-sandbox plugin lefthook "$@"
elif command -v mint >/dev/null 2>&1
then
mint run csjones/lefthook-plugin "$@"
elif command -v npx >/dev/null 2>&1
then
npx lefthook "$@"
else
echo "Can't find lefthook in PATH"
fi
}

call_lefthook run "prepare-commit-msg" "$@"
7 changes: 0 additions & 7 deletions .husky/pre-commit

This file was deleted.

5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@ Testing mocks are split in the `tests` folders.
- `pnpm lint`
- `pnpm lint:fix`

### Duplication

- `pnpm test:duplication`


### Building

- `ember build` (development)
Expand Down
72 changes: 0 additions & 72 deletions app/adapters/application.ts

This file was deleted.

25 changes: 0 additions & 25 deletions app/adapters/user.ts

This file was deleted.

16 changes: 6 additions & 10 deletions app/handlers/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@ export const usersHandlers= [
http.get('http://localhost:8080/api/v1/users/profile', () => {
return HttpResponse.json({
data: {
type: 'users',
id: '1',
attributes: {
email: '',
firstName: '',
lastName: '',
phone: '',
role: '',
},
email: '',
firstName: '',
lastName: '',
phone: '',
role: '',
},
});
}),
Expand All @@ -33,8 +30,7 @@ export const usersHandlers= [
http.post('http://localhost:8080/api/v1/users', () => {
return HttpResponse.json({
data: {
type: 'users',
attributes: {}

}
});
})
Expand Down
7 changes: 2 additions & 5 deletions app/models/document.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Model, { attr, belongsTo } from '@ember-data/model';

import type UserModel from './user';
import { ResourceType } from '@warp-drive/core-types/symbols';

export default class DocumentModel extends Model {
@attr() declare filename: string;
Expand All @@ -15,10 +16,6 @@ export default class DocumentModel extends Model {
async: false,
inverse: 'documents',
}) declare user: UserModel;
}

declare module 'ember-data/types/registries/model' {
export default interface ModelRegistry {
document: DocumentModel;
}
[ResourceType] = 'document' as const;
}
26 changes: 11 additions & 15 deletions app/models/user.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import Model, { attr, hasMany, type SyncHasMany } from '@ember-data/model';

import Model, { attr, hasMany } from '@ember-data/model';
import type DocumentModel from './document';
import { ResourceType } from '@warp-drive/core-types/symbols';

export default class UserModel extends Model {
@attr() declare email: string;
@attr() declare firstName: string;
@attr() declare lastName: string;
@attr() declare phone: string;
@attr() declare role: string;
@attr() declare password: string;
@hasMany('document', {
@attr('string') declare email: string;
@attr('string') declare firstName: string;
@attr('string') declare lastName: string;
@attr('string') declare phone: string;
@attr('string') declare role: string;
@attr('string') declare password: string;
@hasMany<DocumentModel>('document', {
async: false,
inverse: 'user',
}) declare documents: SyncHasMany<DocumentModel>;
}
}) declare documents: DocumentModel[];

declare module 'ember-data/types/registries/model' {
export default interface ModelRegistry {
user: UserModel;
}
[ResourceType] = 'user' as const;
}
1 change: 0 additions & 1 deletion app/modifiers/errors-scroll-up.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { later } from '@ember/runloop';
import { runTask } from 'ember-lifeline';
import type { ValidationError } from 'ember-immer-changeset';

Expand Down
6 changes: 6 additions & 0 deletions app/routes/application.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setBuildURLConfig } from '@ember-data/request-utils';
import { registerDestructor } from '@ember/destroyable';
import Route from '@ember/routing/route';
import { service } from '@ember/service';
Expand All @@ -9,6 +10,11 @@ import type CurrentUserService from 'ember-boilerplate/services/current-user';
import type { IntlService } from 'ember-intl';
import type SessionService from 'ember-simple-auth/services/session';

setBuildURLConfig({
host: config.host,
namespace: config.namespace,
});

export default class Application extends Route {
@service declare session: SessionService;
@service declare currentUser: CurrentUserService;
Expand Down
31 changes: 0 additions & 31 deletions app/serializers/application.ts

This file was deleted.

17 changes: 17 additions & 0 deletions app/services/auth-handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {service} from "@ember/service";
import type SessionService from "./session";
import type { NextFn, RequestContext } from "@ember-data/request";

export default class AuthHandler {
@service declare session: SessionService;

request<T>(context: RequestContext, next: NextFn<T>) {
const headers = new Headers(context.request.headers);
headers.append(
'Authorization',
`Bearer ${this.session.data.authenticated.accessToken}`,
);

return next(Object.assign({}, context.request, { headers }));
}
}
Loading

0 comments on commit 31f31db

Please sign in to comment.